Problem A. Ascending Rating
題意:求一定區間內的上升序列以及最大值,用滑窗求值方法從後往前求就好啦
#include <bits/stdc++.h>
#define INF 70000005
#define ll long long
using namespace std;
int t;
ll n,m,i,j,k,p,q,r,MOD,a[INF],win[INF],sub[INF],cmax,ccou,x,y;
int main(){
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&p,&q,&r,&MOD);
for(i = 1; i <= k; ++i){
scanf("%d",&a[i]);
}
for(i = k+1; i <= n; ++i){
a[i] = (p*a[i-1]+q*i+r)%MOD;
}
cmax = ccou = x = y = 0;
for(int i = n; i > n-m; --i){
if(x == y || a[i] < win[y-1]){
win[y] = a[i];
sub[y++] = i;
}else if(a[i] > win[y-1]){
while(x != y && a[i] > win[y-1]){
y--;
}
win[y] = a[i];
sub[y++] = i;
}
}
cmax += win[x]^(n-m+1);
ccou += (y-x)^(n-m+1);
for(i = n-m; i > 0; --i){
if(sub[x] > i+m-1)
x++;
if(x == y || a[i] < win[y-1]){
win[y] = a[i];
sub[y++] = i;
}else if(a[i] > win[y-1]){
while(x != y && a[i] > win[y-1]){
y--;
}
win[y] = a[i];
sub[y++] = i;
}
cmax += win[x]^i;
ccou += (y-x)^i;;
}
printf("%I64d %I64d\n",cmax,ccou);
}
}
相關文章
- D. Rating System
- 『杭電1810』Rating of Tetris
- A. Arrow a Row
- A. Build a ComputerUI
- A. Least ProductAST
- A. Jagged Swaps
- A. Rudolf and the Ticket
- A. Locked Calculator
- codeforces1450D. Rating Compression
- ATMS中去pause Activity A.
- Codeforces Round #469 C A. Zebras
- Mathematical Problem
- Sum Problem
- 題單5:基礎練習(rating1200)
- Yet Another Problem
- Nanami and the Constructive ProblemNaNStruct
- Prime Ring Problem
- 2019 MCM Problem A
- 火題大戰Vol.1 A.
- # 火題小戰 A.玩個球
- E. Not a Nim Problem
- Nanami and the House Protecting ProblemNaN
- HDU - 6182 A Math Problem
- Fixed "There was a problem with the editor 'vi'"
- Prime Ring Problem (dfs)
- P1865 A % B Problem
- Assignment Problem的若干思考
- A + B Problem II hd 1002
- Joe Harris is a real problem with this team
- Follow/Unfollow problem in system design
- Euclid Problem - PC110703
- HDU 1002 A + B Problem II
- POJ 2355 Railway Ticket problemAI
- The Door Problem 並查集並查集
- HDU 1792 A New Change Problem
- Codeforces Beta Round #76 (Div. 1 Only) A. Frames
- ESTR1002 Problem Solving by Programming
- ECE 498/598 Associative Recall Problem