Submission #939898

# Submission time Handle Problem Language Result Execution time Memory
939898 2024-03-06T23:17:52 Z Edu175 Abracadabra (CEOI22_abracadabra) C++17
100 / 100
809 ms 72068 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};
}*/
ii find(ll x){
	ll p=0;
	for(ll k=19;k>=0;k--)if(ft[p+(1ll<<k)]<=x){
		p+=1ll<<k;
		x-=ft[p];
	}
	return {p,x};
}
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;
}
# Verdict Execution time Memory Grader output
1 Correct 398 ms 45764 KB Output is correct
2 Correct 474 ms 43500 KB Output is correct
3 Correct 396 ms 42616 KB Output is correct
4 Correct 349 ms 39280 KB Output is correct
5 Correct 423 ms 46208 KB Output is correct
6 Correct 355 ms 43356 KB Output is correct
7 Correct 409 ms 48224 KB Output is correct
8 Correct 356 ms 42268 KB Output is correct
9 Correct 363 ms 40960 KB Output is correct
10 Correct 365 ms 40976 KB Output is correct
11 Correct 356 ms 40588 KB Output is correct
12 Correct 369 ms 39156 KB Output is correct
13 Correct 353 ms 40128 KB Output is correct
14 Correct 371 ms 43348 KB Output is correct
15 Correct 371 ms 40920 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 372 ms 40060 KB Output is correct
18 Correct 336 ms 38612 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 582 ms 61456 KB Output is correct
2 Correct 558 ms 62124 KB Output is correct
3 Correct 454 ms 53732 KB Output is correct
4 Correct 440 ms 53524 KB Output is correct
5 Correct 448 ms 55300 KB Output is correct
6 Correct 429 ms 52888 KB Output is correct
7 Correct 545 ms 61224 KB Output is correct
8 Correct 517 ms 58884 KB Output is correct
9 Correct 461 ms 54356 KB Output is correct
10 Correct 498 ms 58176 KB Output is correct
11 Correct 403 ms 52152 KB Output is correct
12 Correct 403 ms 51780 KB Output is correct
13 Correct 486 ms 57852 KB Output is correct
14 Correct 421 ms 52396 KB Output is correct
15 Correct 508 ms 60072 KB Output is correct
16 Correct 51 ms 19284 KB Output is correct
17 Correct 461 ms 55848 KB Output is correct
18 Correct 356 ms 47064 KB Output is correct
19 Correct 137 ms 25064 KB Output is correct
20 Correct 159 ms 27828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 19284 KB Output is correct
2 Correct 96 ms 19024 KB Output is correct
3 Correct 92 ms 18708 KB Output is correct
4 Correct 74 ms 18660 KB Output is correct
5 Correct 85 ms 19104 KB Output is correct
6 Correct 78 ms 17236 KB Output is correct
7 Correct 89 ms 19004 KB Output is correct
8 Correct 79 ms 18748 KB Output is correct
9 Correct 82 ms 18772 KB Output is correct
10 Correct 69 ms 18512 KB Output is correct
11 Correct 77 ms 19088 KB Output is correct
12 Correct 69 ms 18596 KB Output is correct
13 Correct 73 ms 18296 KB Output is correct
14 Correct 72 ms 18772 KB Output is correct
15 Correct 69 ms 16720 KB Output is correct
16 Correct 25 ms 13908 KB Output is correct
17 Correct 76 ms 17272 KB Output is correct
18 Correct 63 ms 15216 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 45764 KB Output is correct
2 Correct 474 ms 43500 KB Output is correct
3 Correct 396 ms 42616 KB Output is correct
4 Correct 349 ms 39280 KB Output is correct
5 Correct 423 ms 46208 KB Output is correct
6 Correct 355 ms 43356 KB Output is correct
7 Correct 409 ms 48224 KB Output is correct
8 Correct 356 ms 42268 KB Output is correct
9 Correct 363 ms 40960 KB Output is correct
10 Correct 365 ms 40976 KB Output is correct
11 Correct 356 ms 40588 KB Output is correct
12 Correct 369 ms 39156 KB Output is correct
13 Correct 353 ms 40128 KB Output is correct
14 Correct 371 ms 43348 KB Output is correct
15 Correct 371 ms 40920 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 372 ms 40060 KB Output is correct
18 Correct 336 ms 38612 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 582 ms 61456 KB Output is correct
22 Correct 558 ms 62124 KB Output is correct
23 Correct 454 ms 53732 KB Output is correct
24 Correct 440 ms 53524 KB Output is correct
25 Correct 448 ms 55300 KB Output is correct
26 Correct 429 ms 52888 KB Output is correct
27 Correct 545 ms 61224 KB Output is correct
28 Correct 517 ms 58884 KB Output is correct
29 Correct 461 ms 54356 KB Output is correct
30 Correct 498 ms 58176 KB Output is correct
31 Correct 403 ms 52152 KB Output is correct
32 Correct 403 ms 51780 KB Output is correct
33 Correct 486 ms 57852 KB Output is correct
34 Correct 421 ms 52396 KB Output is correct
35 Correct 508 ms 60072 KB Output is correct
36 Correct 51 ms 19284 KB Output is correct
37 Correct 461 ms 55848 KB Output is correct
38 Correct 356 ms 47064 KB Output is correct
39 Correct 137 ms 25064 KB Output is correct
40 Correct 159 ms 27828 KB Output is correct
41 Correct 93 ms 19284 KB Output is correct
42 Correct 96 ms 19024 KB Output is correct
43 Correct 92 ms 18708 KB Output is correct
44 Correct 74 ms 18660 KB Output is correct
45 Correct 85 ms 19104 KB Output is correct
46 Correct 78 ms 17236 KB Output is correct
47 Correct 89 ms 19004 KB Output is correct
48 Correct 79 ms 18748 KB Output is correct
49 Correct 82 ms 18772 KB Output is correct
50 Correct 69 ms 18512 KB Output is correct
51 Correct 77 ms 19088 KB Output is correct
52 Correct 69 ms 18596 KB Output is correct
53 Correct 73 ms 18296 KB Output is correct
54 Correct 72 ms 18772 KB Output is correct
55 Correct 69 ms 16720 KB Output is correct
56 Correct 25 ms 13908 KB Output is correct
57 Correct 76 ms 17272 KB Output is correct
58 Correct 63 ms 15216 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 1 ms 6492 KB Output is correct
61 Correct 809 ms 70748 KB Output is correct
62 Correct 740 ms 71652 KB Output is correct
63 Correct 737 ms 69072 KB Output is correct
64 Correct 600 ms 69480 KB Output is correct
65 Correct 650 ms 72068 KB Output is correct
66 Correct 594 ms 69328 KB Output is correct
67 Correct 569 ms 68692 KB Output is correct
68 Correct 570 ms 66256 KB Output is correct
69 Correct 612 ms 70088 KB Output is correct
70 Correct 561 ms 63592 KB Output is correct
71 Correct 520 ms 66520 KB Output is correct
72 Correct 556 ms 64604 KB Output is correct
73 Correct 536 ms 65472 KB Output is correct
74 Correct 577 ms 69256 KB Output is correct
75 Correct 571 ms 65416 KB Output is correct
76 Correct 55 ms 19124 KB Output is correct
77 Correct 590 ms 56736 KB Output is correct
78 Correct 457 ms 53680 KB Output is correct
79 Correct 1 ms 6488 KB Output is correct
80 Correct 1 ms 6492 KB Output is correct