QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307267#7627. Phony275307894a#WA 2ms10100kbC++142.4kb2024-01-18 12:05:532024-01-18 12:05:54

Judging History

你现在查看的是最新测评结果

  • [2024-01-18 12:05:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10100kb
  • [2024-01-18 12:05:53]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e5+5,M=N*4+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m;ll k,A[N];
int l[N],r[N],siz[N],rd[N],cnt;ll val[N],g[N];
void Pg(int v,ll w){if(v) val[v]+=w,g[v]+=w;}
void P(int v){if(g[v]) Pg(l[v],g[v]),Pg(r[v],g[v]),g[v]=0;}
void up(int v){siz[v]=siz[l[v]]+siz[r[v]]+1;}
void split1(ll x,int v,int &a,int &b){
	if(!v){a=b=0;return;}P(v);
	if(x>=val[v]) a=v,split1(x,r[v],r[a],b);
	else b=v,split1(x,l[v],a,l[b]);
	up(v);
}
void split2(int x,int v,int &a,int &b){
	if(!v){a=b=0;return;}P(v);
	if(x>=siz[l[v]]+1) a=v,split2(x-siz[l[v]]-1,r[v],r[a],b);
	else b=v,split2(x,l[v],a,l[b]);
	up(v);
}
ll qry(int x,int v){
	P(v);
	if(x==siz[r[v]]+1) return val[v];
	if(x>siz[r[v]]+1) return qry(x-siz[r[v]]-1,l[v]);
	else return qry(x,r[v]);
}
int newn(ll x){siz[++cnt]=1;rd[cnt]=rnd();val[cnt]=x;return cnt;}
int merge(int x,int y){
	if(!x||!y) return x|y;P(x);P(y);
	if(rd[x]<rd[y]) return r[x]=merge(r[x],y),up(x),x;
	else return l[y]=merge(x,l[y]),up(y),y;
}
int qi(int x){while(l[x]) P(x),x=l[x];return val[x];}
int qx(int x){while(r[x]) P(x),x=r[x];return val[x];}
int rt;
using LL=__int128;
void Solve(){
	int i,j;scanf("%d%d%lld",&n,&m,&k);
	for(i=1;i<=n;i++) scanf("%lld",&A[i]);
	sort(A+1,A+n+1);
	int R=n-1;rt=newn(A[n]);
	while(m--){
		char c;c=Gc();while(c<'A'||c>'Z') c=Gc();
		ll x;scanf("%lld",&x);
		if(c=='C'){
			while(R){
				LL w=(LL)(qi(rt)-A[R])/k*(n-R);
				if(w>x) break;
				Pg(rt,-(qi(rt)-A[R])/k*k);x-=w;
				int r1,r2;split1(A[R]+k-1,rt,r1,r2);
				if(siz[r2]<=k){
					Pg(r2,-k);x-=siz[r2];
					rt=merge(merge(newn(A[R]),r2),r1);
					R--;
				}else{rt=merge(r1,r2);break;}
			}
			ll w=x/(n-R);
			Pg(rt,-w*k);x-=w*(n-R);
			int r1,r2;split2((n-R)-x,rt,r1,r2);
			Pg(r2,-k);rt=merge(r2,r1);
		}else{
			printf("%lld\n",x<=n-R?qry(x,rt):A[n-x+1]);
		}
	}
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10100kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 10052kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 10092kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9161
4721
8054
2945
7483
7324
5291
5001
2042
4721
4721
6348
4097
6502
6535
6357
6307
811
5899
2561
5853
5192
5121
3581
4922
1485
4938
4391
2042
4110
3851
3893
3697
3585
3291
3296
2993
3170
2987
3086
2042
2960
2871
2998
2699
2409
2579
115
2042
2538
2042
2532
1485
2574
-18826

result:

wrong answer 4th lines differ - expected: '8200', found: '8054'