#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) begin(x),end(x)
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
//--------------------------------------------//
int N,Q;
vi a;
void ckmax(int &x, int y){x=max(x,y);}
const int MX=5e5+10;
vi t(MX,0);
void upd(int i){
for(;i<MX; i+=i&-i) t[i]++;
}
int get(int i){
int ans=0;
for(;i;i-=i&-i) ans+=t[i];
return ans;
}
vi countScans(vi A,vi X,vi V){
N=sz(A); Q=sz(X);
a.assign(all(A));
vi temp;
temp.assign(all(a));
FOR(i,0,Q) temp.pb(V[i]);
sort(all(temp));
unordered_map<int,int>mp;
int cnt=0;
for(int x: temp) if(!mp.count(x)) mp[x]=++cnt;
FOR(i,0,N) a[i]=mp[a[i]];
FOR(i,0,Q) V[i]=mp[V[i]];
vi ans(Q,0);
FOR(idx,0,Q){
a[X[idx]]=V[idx];
vi st,vec(N);
ROF(i,0,N){
while(sz(st) && st.back()<a[i]) st.pop_back();
if(!sz(st)){
vec[i]=(i!=N-1);
}
else{
if(st.back()==i+1 && !vec[st.back()])
vec[i]=0;
else vec[i]=vec[st.back()]+1;
}
st.pb(i);
}
FOR(i,0,N+Q+1) t[i]=0;
FOR(i,0,N){
ckmax(vec[i],i-get(a[i]));
upd(a[i]);
}
FOR(i,0,N) ckmax(ans[idx],vec[i]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2252 KB |
Output is correct |
2 |
Correct |
40 ms |
2264 KB |
Output is correct |
3 |
Correct |
218 ms |
2508 KB |
Output is correct |
4 |
Correct |
222 ms |
2508 KB |
Output is correct |
5 |
Correct |
221 ms |
2488 KB |
Output is correct |
6 |
Correct |
201 ms |
2508 KB |
Output is correct |
7 |
Correct |
206 ms |
2508 KB |
Output is correct |
8 |
Correct |
211 ms |
2536 KB |
Output is correct |
9 |
Correct |
215 ms |
2532 KB |
Output is correct |
10 |
Correct |
197 ms |
2508 KB |
Output is correct |
11 |
Correct |
196 ms |
2508 KB |
Output is correct |
12 |
Correct |
201 ms |
2528 KB |
Output is correct |
13 |
Correct |
196 ms |
2508 KB |
Output is correct |
14 |
Correct |
196 ms |
2520 KB |
Output is correct |
15 |
Correct |
199 ms |
2516 KB |
Output is correct |
16 |
Correct |
196 ms |
2508 KB |
Output is correct |
17 |
Correct |
198 ms |
2508 KB |
Output is correct |
18 |
Correct |
199 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2252 KB |
Output is correct |
2 |
Correct |
40 ms |
2264 KB |
Output is correct |
3 |
Correct |
218 ms |
2508 KB |
Output is correct |
4 |
Correct |
222 ms |
2508 KB |
Output is correct |
5 |
Correct |
221 ms |
2488 KB |
Output is correct |
6 |
Correct |
201 ms |
2508 KB |
Output is correct |
7 |
Correct |
206 ms |
2508 KB |
Output is correct |
8 |
Correct |
211 ms |
2536 KB |
Output is correct |
9 |
Correct |
215 ms |
2532 KB |
Output is correct |
10 |
Correct |
197 ms |
2508 KB |
Output is correct |
11 |
Correct |
196 ms |
2508 KB |
Output is correct |
12 |
Correct |
201 ms |
2528 KB |
Output is correct |
13 |
Correct |
196 ms |
2508 KB |
Output is correct |
14 |
Correct |
196 ms |
2520 KB |
Output is correct |
15 |
Correct |
199 ms |
2516 KB |
Output is correct |
16 |
Correct |
196 ms |
2508 KB |
Output is correct |
17 |
Correct |
198 ms |
2508 KB |
Output is correct |
18 |
Correct |
199 ms |
2508 KB |
Output is correct |
19 |
Correct |
2677 ms |
3316 KB |
Output is correct |
20 |
Correct |
3469 ms |
3444 KB |
Output is correct |
21 |
Correct |
3292 ms |
3448 KB |
Output is correct |
22 |
Correct |
3325 ms |
3444 KB |
Output is correct |
23 |
Correct |
3077 ms |
3384 KB |
Output is correct |
24 |
Correct |
3113 ms |
3384 KB |
Output is correct |
25 |
Correct |
3146 ms |
3348 KB |
Output is correct |
26 |
Correct |
3151 ms |
3348 KB |
Output is correct |
27 |
Correct |
3168 ms |
3324 KB |
Output is correct |
28 |
Correct |
3110 ms |
3396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3099 ms |
3524 KB |
Output is correct |
2 |
Execution timed out |
9024 ms |
4344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2252 KB |
Output is correct |
2 |
Correct |
40 ms |
2264 KB |
Output is correct |
3 |
Correct |
218 ms |
2508 KB |
Output is correct |
4 |
Correct |
222 ms |
2508 KB |
Output is correct |
5 |
Correct |
221 ms |
2488 KB |
Output is correct |
6 |
Correct |
201 ms |
2508 KB |
Output is correct |
7 |
Correct |
206 ms |
2508 KB |
Output is correct |
8 |
Correct |
211 ms |
2536 KB |
Output is correct |
9 |
Correct |
215 ms |
2532 KB |
Output is correct |
10 |
Correct |
197 ms |
2508 KB |
Output is correct |
11 |
Correct |
196 ms |
2508 KB |
Output is correct |
12 |
Correct |
201 ms |
2528 KB |
Output is correct |
13 |
Correct |
196 ms |
2508 KB |
Output is correct |
14 |
Correct |
196 ms |
2520 KB |
Output is correct |
15 |
Correct |
199 ms |
2516 KB |
Output is correct |
16 |
Correct |
196 ms |
2508 KB |
Output is correct |
17 |
Correct |
198 ms |
2508 KB |
Output is correct |
18 |
Correct |
199 ms |
2508 KB |
Output is correct |
19 |
Correct |
2677 ms |
3316 KB |
Output is correct |
20 |
Correct |
3469 ms |
3444 KB |
Output is correct |
21 |
Correct |
3292 ms |
3448 KB |
Output is correct |
22 |
Correct |
3325 ms |
3444 KB |
Output is correct |
23 |
Correct |
3077 ms |
3384 KB |
Output is correct |
24 |
Correct |
3113 ms |
3384 KB |
Output is correct |
25 |
Correct |
3146 ms |
3348 KB |
Output is correct |
26 |
Correct |
3151 ms |
3348 KB |
Output is correct |
27 |
Correct |
3168 ms |
3324 KB |
Output is correct |
28 |
Correct |
3110 ms |
3396 KB |
Output is correct |
29 |
Correct |
3099 ms |
3524 KB |
Output is correct |
30 |
Execution timed out |
9024 ms |
4344 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |