답안 #936480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936480 2024-03-01T23:34:30 Z Edu175 Abracadabra (CEOI22_abracadabra) C++17
100 / 100
1035 ms 71932 KB
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ceoi=b;i<ceoi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) for(auto kdjfhg:v)cout<<kdjfhg<<" ";cout<<"\n"
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=1e6+5;

ll ft[MAXN],arr[MAXN];
ll n;
void upd(ll i, ll v){
	//cout<<"new "<<i<<" "<<v<<"\n";
	arr[i]+=v;
	for(i++;i<=MAXN;i+=i&-i)ft[i]+=v;
}
ll get_sum(ll i){ // )
	ll res=0;
	for(;i;i-=i&-i)res+=ft[i];
	return res;
}
ii find(ll x){ //upperbound on prefix sums, (pos,remainder)
	ll l=0,r=n-1;
	while(l<=r){
		ll m=(l+r)/2;
		if(get_sum(m+1)>x)r=m-1;
		else l=m+1;
	}
	r=x-get_sum(l);
	//cout<<"find "<<x<<": "<<l<<","<<r<<endl;
	//fore(i,0,n)cout<<arr[i]<<" ";;cout<<endl;
	return {l,r};
}
int main(){
	ll q; cin>>n>>q;
	vector<ll>a(n),p(n);
	fore(i,0,n)cin>>a[i],a[i]--,p[a[i]]=i;
	vector<vector<ii>>qs(n+5);
	vector<ll>ans(q);
	fore(_,0,q){
		ll t,i; cin>>t>>i; i--;
		t=min(t,n+3);
		qs[t].pb({i,_});
	}
	vector<ll>nx(n);
	for(ll i=n-1;i>=0;i--)
		for(nx[i]=i+1;nx[i]!=n&&a[i]>=a[nx[i]];nx[i]=nx[nx[i]]);
	ll mx=0;
	fore(i,0,n){
		mx=max(mx,a[i]);
		if(a[i]==mx)upd(a[i],nx[i]-i);
	}
	//fore(i,0,n)cout<<nx[i]<<" ";;cout<<"\n";
	fore(t,0,n+5){
		//cout<<"time "<<t<<endl;
		for(auto [i,_]:qs[t]){
			auto [x,r]=find(i);
			ans[_]=a[p[x]+r];
		}
		auto [x,r]=find(n/2);
		if(r==0)continue; //x==i
		ll z=arr[x];
		upd(x,-z+r);
		//cout<<nx[p[x]]<<")\n";
		for(ll i=p[x]+r;i<p[x]+z;i=nx[i])upd(a[i],min(nx[i],p[x]+z)-i);
	}
	fore(_,0,q)cout<<ans[_]+1<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 486 ms 38160 KB Output is correct
2 Correct 501 ms 43424 KB Output is correct
3 Correct 470 ms 42448 KB Output is correct
4 Correct 374 ms 39304 KB Output is correct
5 Correct 411 ms 46180 KB Output is correct
6 Correct 395 ms 43304 KB Output is correct
7 Correct 423 ms 48000 KB Output is correct
8 Correct 395 ms 42164 KB Output is correct
9 Correct 421 ms 40964 KB Output is correct
10 Correct 420 ms 41120 KB Output is correct
11 Correct 395 ms 40776 KB Output is correct
12 Correct 369 ms 38500 KB Output is correct
13 Correct 388 ms 40280 KB Output is correct
14 Correct 413 ms 43588 KB Output is correct
15 Correct 400 ms 40884 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 425 ms 38980 KB Output is correct
18 Correct 362 ms 38528 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 779 ms 47320 KB Output is correct
2 Correct 714 ms 61724 KB Output is correct
3 Correct 597 ms 53264 KB Output is correct
4 Correct 607 ms 52400 KB Output is correct
5 Correct 654 ms 52100 KB Output is correct
6 Correct 640 ms 50104 KB Output is correct
7 Correct 669 ms 61548 KB Output is correct
8 Correct 693 ms 57636 KB Output is correct
9 Correct 620 ms 54052 KB Output is correct
10 Correct 677 ms 58896 KB Output is correct
11 Correct 518 ms 50604 KB Output is correct
12 Correct 575 ms 49096 KB Output is correct
13 Correct 707 ms 57152 KB Output is correct
14 Correct 554 ms 51744 KB Output is correct
15 Correct 773 ms 57696 KB Output is correct
16 Correct 91 ms 19400 KB Output is correct
17 Correct 615 ms 56376 KB Output is correct
18 Correct 493 ms 46760 KB Output is correct
19 Correct 204 ms 25816 KB Output is correct
20 Correct 235 ms 26508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 18516 KB Output is correct
2 Correct 120 ms 19216 KB Output is correct
3 Correct 118 ms 18676 KB Output is correct
4 Correct 112 ms 18576 KB Output is correct
5 Correct 116 ms 19048 KB Output is correct
6 Correct 114 ms 17096 KB Output is correct
7 Correct 103 ms 19028 KB Output is correct
8 Correct 104 ms 18700 KB Output is correct
9 Correct 124 ms 19040 KB Output is correct
10 Correct 95 ms 18516 KB Output is correct
11 Correct 89 ms 19024 KB Output is correct
12 Correct 95 ms 18512 KB Output is correct
13 Correct 107 ms 18596 KB Output is correct
14 Correct 93 ms 19028 KB Output is correct
15 Correct 102 ms 16728 KB Output is correct
16 Correct 37 ms 14072 KB Output is correct
17 Correct 102 ms 17476 KB Output is correct
18 Correct 93 ms 15360 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 486 ms 38160 KB Output is correct
2 Correct 501 ms 43424 KB Output is correct
3 Correct 470 ms 42448 KB Output is correct
4 Correct 374 ms 39304 KB Output is correct
5 Correct 411 ms 46180 KB Output is correct
6 Correct 395 ms 43304 KB Output is correct
7 Correct 423 ms 48000 KB Output is correct
8 Correct 395 ms 42164 KB Output is correct
9 Correct 421 ms 40964 KB Output is correct
10 Correct 420 ms 41120 KB Output is correct
11 Correct 395 ms 40776 KB Output is correct
12 Correct 369 ms 38500 KB Output is correct
13 Correct 388 ms 40280 KB Output is correct
14 Correct 413 ms 43588 KB Output is correct
15 Correct 400 ms 40884 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 425 ms 38980 KB Output is correct
18 Correct 362 ms 38528 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 779 ms 47320 KB Output is correct
22 Correct 714 ms 61724 KB Output is correct
23 Correct 597 ms 53264 KB Output is correct
24 Correct 607 ms 52400 KB Output is correct
25 Correct 654 ms 52100 KB Output is correct
26 Correct 640 ms 50104 KB Output is correct
27 Correct 669 ms 61548 KB Output is correct
28 Correct 693 ms 57636 KB Output is correct
29 Correct 620 ms 54052 KB Output is correct
30 Correct 677 ms 58896 KB Output is correct
31 Correct 518 ms 50604 KB Output is correct
32 Correct 575 ms 49096 KB Output is correct
33 Correct 707 ms 57152 KB Output is correct
34 Correct 554 ms 51744 KB Output is correct
35 Correct 773 ms 57696 KB Output is correct
36 Correct 91 ms 19400 KB Output is correct
37 Correct 615 ms 56376 KB Output is correct
38 Correct 493 ms 46760 KB Output is correct
39 Correct 204 ms 25816 KB Output is correct
40 Correct 235 ms 26508 KB Output is correct
41 Correct 118 ms 18516 KB Output is correct
42 Correct 120 ms 19216 KB Output is correct
43 Correct 118 ms 18676 KB Output is correct
44 Correct 112 ms 18576 KB Output is correct
45 Correct 116 ms 19048 KB Output is correct
46 Correct 114 ms 17096 KB Output is correct
47 Correct 103 ms 19028 KB Output is correct
48 Correct 104 ms 18700 KB Output is correct
49 Correct 124 ms 19040 KB Output is correct
50 Correct 95 ms 18516 KB Output is correct
51 Correct 89 ms 19024 KB Output is correct
52 Correct 95 ms 18512 KB Output is correct
53 Correct 107 ms 18596 KB Output is correct
54 Correct 93 ms 19028 KB Output is correct
55 Correct 102 ms 16728 KB Output is correct
56 Correct 37 ms 14072 KB Output is correct
57 Correct 102 ms 17476 KB Output is correct
58 Correct 93 ms 15360 KB Output is correct
59 Correct 1 ms 6488 KB Output is correct
60 Correct 1 ms 6492 KB Output is correct
61 Correct 1035 ms 70632 KB Output is correct
62 Correct 1035 ms 71932 KB Output is correct
63 Correct 963 ms 69360 KB Output is correct
64 Correct 859 ms 69588 KB Output is correct
65 Correct 861 ms 70612 KB Output is correct
66 Correct 868 ms 67776 KB Output is correct
67 Correct 759 ms 66636 KB Output is correct
68 Correct 799 ms 64780 KB Output is correct
69 Correct 815 ms 70396 KB Output is correct
70 Correct 839 ms 63884 KB Output is correct
71 Correct 677 ms 65048 KB Output is correct
72 Correct 768 ms 62884 KB Output is correct
73 Correct 760 ms 64400 KB Output is correct
74 Correct 723 ms 69080 KB Output is correct
75 Correct 775 ms 64292 KB Output is correct
76 Correct 80 ms 19284 KB Output is correct
77 Correct 783 ms 56264 KB Output is correct
78 Correct 648 ms 53756 KB Output is correct
79 Correct 1 ms 6492 KB Output is correct
80 Correct 1 ms 6492 KB Output is correct