#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int H=20;
const int N=(1<<H);
vi dif;
int seg[N*2], laz[N];
int width[N*2];
void fillW(int p=1, int w=N) {
width[p] = w;
if(w == 1) return;
fillW(p*2,w/2);
fillW(p*2+1,w/2);
}
void apply(int p, int v) {
seg[p] += v*width[p];
if(p < N) laz[p] += v;
}
void build(int p) {
while(p>1) p/=2, seg[p]=seg[p*2]+seg[p*2+1]+laz[p]*width[p];
}
void push(int p) {
REV(s,1,H+1) {
int i=p>>s;
apply(i*2 ,laz[i]);
apply(i*2+1,laz[i]);
laz[i] = 0;
}
}
void add(int l, int r, int v) {
int l0=l+=N, r0=r+=N;
for(; l<r; l/=2, r/=2) {
if(l&1) apply(l++,v);
if(r&1) apply(--r,v);
}
build(l0);
build(r0-1);
}
int get(int l, int r) {
l+=N; r+=N;
push(l);
push(r-1);
int res=0;
for(; l<r; l/=2, r/=2) {
if(l&1) res += seg[l++];
if(r&1) res += seg[--r];
}
return res;
}
vi countScans(vi A, vi X, vi V){
fillW();
int n=A.size();
int q=X.size();
vi ans(q);
RE(i,n) dif.pb(A[i]);
RE(i,q) dif.pb(V[i]);
sort(all(dif));
dif.erase(unique(all(dif)), dif.end());
RE(i,n) A[i] = lower_bound(all(dif), A[i])-dif.begin();
RE(i,q) V[i] = lower_bound(all(dif), V[i])-dif.begin();
RE(i,n) add(A[i],N,1);
RE(j,q) {
add(A[X[j]],N,-1);
A[X[j]] = V[j];
add(A[X[j]],N, 1);
int cAns = 0;
RE(i,n)
cAns = max(cAns, i-int(get(A[i],A[i]+1) - 1));
ans[j] = cAns;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
8824 KB |
Output is correct |
2 |
Correct |
244 ms |
8756 KB |
Output is correct |
3 |
Correct |
1010 ms |
8824 KB |
Output is correct |
4 |
Correct |
1012 ms |
8824 KB |
Output is correct |
5 |
Correct |
1038 ms |
8952 KB |
Output is correct |
6 |
Correct |
1167 ms |
8824 KB |
Output is correct |
7 |
Correct |
1140 ms |
8832 KB |
Output is correct |
8 |
Correct |
1118 ms |
8824 KB |
Output is correct |
9 |
Correct |
1018 ms |
8824 KB |
Output is correct |
10 |
Correct |
1219 ms |
8820 KB |
Output is correct |
11 |
Correct |
1227 ms |
8824 KB |
Output is correct |
12 |
Correct |
1230 ms |
8824 KB |
Output is correct |
13 |
Correct |
1214 ms |
8824 KB |
Output is correct |
14 |
Correct |
1223 ms |
8824 KB |
Output is correct |
15 |
Correct |
1222 ms |
8824 KB |
Output is correct |
16 |
Correct |
1229 ms |
8824 KB |
Output is correct |
17 |
Correct |
1226 ms |
8828 KB |
Output is correct |
18 |
Correct |
1212 ms |
8824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
8824 KB |
Output is correct |
2 |
Correct |
244 ms |
8756 KB |
Output is correct |
3 |
Correct |
1010 ms |
8824 KB |
Output is correct |
4 |
Correct |
1012 ms |
8824 KB |
Output is correct |
5 |
Correct |
1038 ms |
8952 KB |
Output is correct |
6 |
Correct |
1167 ms |
8824 KB |
Output is correct |
7 |
Correct |
1140 ms |
8832 KB |
Output is correct |
8 |
Correct |
1118 ms |
8824 KB |
Output is correct |
9 |
Correct |
1018 ms |
8824 KB |
Output is correct |
10 |
Correct |
1219 ms |
8820 KB |
Output is correct |
11 |
Correct |
1227 ms |
8824 KB |
Output is correct |
12 |
Correct |
1230 ms |
8824 KB |
Output is correct |
13 |
Correct |
1214 ms |
8824 KB |
Output is correct |
14 |
Correct |
1223 ms |
8824 KB |
Output is correct |
15 |
Correct |
1222 ms |
8824 KB |
Output is correct |
16 |
Correct |
1229 ms |
8824 KB |
Output is correct |
17 |
Correct |
1226 ms |
8828 KB |
Output is correct |
18 |
Correct |
1212 ms |
8824 KB |
Output is correct |
19 |
Execution timed out |
9036 ms |
9088 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
9039 ms |
9088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
8824 KB |
Output is correct |
2 |
Correct |
244 ms |
8756 KB |
Output is correct |
3 |
Correct |
1010 ms |
8824 KB |
Output is correct |
4 |
Correct |
1012 ms |
8824 KB |
Output is correct |
5 |
Correct |
1038 ms |
8952 KB |
Output is correct |
6 |
Correct |
1167 ms |
8824 KB |
Output is correct |
7 |
Correct |
1140 ms |
8832 KB |
Output is correct |
8 |
Correct |
1118 ms |
8824 KB |
Output is correct |
9 |
Correct |
1018 ms |
8824 KB |
Output is correct |
10 |
Correct |
1219 ms |
8820 KB |
Output is correct |
11 |
Correct |
1227 ms |
8824 KB |
Output is correct |
12 |
Correct |
1230 ms |
8824 KB |
Output is correct |
13 |
Correct |
1214 ms |
8824 KB |
Output is correct |
14 |
Correct |
1223 ms |
8824 KB |
Output is correct |
15 |
Correct |
1222 ms |
8824 KB |
Output is correct |
16 |
Correct |
1229 ms |
8824 KB |
Output is correct |
17 |
Correct |
1226 ms |
8828 KB |
Output is correct |
18 |
Correct |
1212 ms |
8824 KB |
Output is correct |
19 |
Execution timed out |
9036 ms |
9088 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |