// #include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
vector<int> a;
int n;
struct Node{
int val=0;
int lazy=0;
Node* left,*right;
bool islazy=false;
Node() : left(nullptr),right(nullptr) {}
};
Node* root;
void build(Node* node,int l,int r){
if(l==r) return;
int mid=(l+r)/2;
node->left=new Node();
node->right=new Node();
build(node->left,l,mid);
build(node->right,mid+1,r);
}
void push(Node* node,int l,int r){
if(!node->islazy) return;
node->islazy=false;
node->val+=node->lazy;
if(l!=r){
if(node->left) {
node->left->islazy=true;
node->left->lazy+=node->lazy;
}
if(node->right) {
node->right->islazy=true;
node->right->lazy+=node->lazy;
}
}
node->lazy=0;
}
void p(Node* node,int l,int r){
push(node,l,r);
int mid=(l+r)/2;
if(l==r) return;
if(node->left) push(node->left,l,mid);
if(node->right) push(node->right,mid+1,r);
}
void update(Node* node,int l,int r,int ql,int qr,int x){
p(node,l,r);
if(ql>r||qr<l) return;
if(ql<=l&&r<=qr){
node->islazy=true;
node->lazy+=x;
p(node,l,r);
return;
}
int mid=(l+r)/2;
if(ql<=mid) update(node->left,l,mid,ql,qr,x);
if(qr>mid) update(node->right,mid+1,r,ql,qr,x);
node->val=max(node->left->val,node->right->val);
}
vector<int> countScans(vector<int> A,vector<int> x,vector<int> y){
a=A;
root=new Node();
n=a.size();
int q=x.size();
build(root,0,n+q);
vector<pii> v;
for(int i=0;i<n;i++){
v.pb({a[i],i});
}
for(int i=0;i<q;i++){
v.pb({y[i],x[i]});
}
sort(all(v));
for(int i=0;i<n;i++){
a[i]=find(all(v),make_pair(a[i],i))-v.begin();
}
for(int i=0;i<q;i++){
y[i]=find(all(v),make_pair(y[i],x[i]))-v.begin();
}
// dbg(a,y)
vector<int> Ans(q);
int sz=n+q;
auto ch = [&](int i,int x){
update(root,0,sz,a[i],a[i],i*x);
update(root,0,sz,a[i]+1,sz,-x);
};
for(int i=0;i<n;i++){
ch(i,1);
// update(root,0,sz,a[i],a[i],i);
// update(root,0,sz,a[i]+1,sz,-1);
}
// dbg(root->val)
for(int i=0;i<q;i++){
ch(x[i],-1);
// update(root,0,sz,a[x[i]],a[x[i]],-i);
// update(root,0,sz,a[x[i]]+1,sz,1);
// dbg(root->val)
a[x[i]]=y[i];
ch(x[i],1);
// update(root,0,sz,a[x[i]],a[x[i]],i);
// dbg(root->val)
// update(root,0,sz,a[x[i]]+1,sz,-1);
// dbg(root->val)
Ans[i]=root->val;
}
return Ans;
}
#ifdef IOI
// #include "bubblesort2.h"
// #include <cstdio>
// #include <cstdlib>
// #include <vector>
int readInt(){
int i;
if(scanf("%d",&i)!=1){
fprintf(stderr,"Error while reading input\n");
exit(1);
}
return i;
}
int main(){
int N,Q;
N=readInt();
Q=readInt();
vector<int> A(N);
for(int i=0;i<N;i++)
A[i]=readInt();
vector<int> X(Q),V(Q);
for(int j=0;j<Q;j++){
X[j]=readInt();
V[j]=readInt();
}
vector<int> res=countScans(A,X,V);
for(int j=0;j<int(res.size());j++)
printf("%d\n",res[j]);
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
6 ms |
956 KB |
Output is correct |
5 |
Correct |
6 ms |
860 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
6 ms |
744 KB |
Output is correct |
8 |
Correct |
5 ms |
968 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
4 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
968 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
960 KB |
Output is correct |
18 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
6 ms |
956 KB |
Output is correct |
5 |
Correct |
6 ms |
860 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
6 ms |
744 KB |
Output is correct |
8 |
Correct |
5 ms |
968 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
4 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
968 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
960 KB |
Output is correct |
18 |
Correct |
5 ms |
860 KB |
Output is correct |
19 |
Correct |
36 ms |
2248 KB |
Output is correct |
20 |
Correct |
47 ms |
2396 KB |
Output is correct |
21 |
Correct |
52 ms |
2392 KB |
Output is correct |
22 |
Correct |
47 ms |
2396 KB |
Output is correct |
23 |
Correct |
46 ms |
2396 KB |
Output is correct |
24 |
Correct |
46 ms |
2396 KB |
Output is correct |
25 |
Correct |
46 ms |
2396 KB |
Output is correct |
26 |
Correct |
46 ms |
2392 KB |
Output is correct |
27 |
Correct |
64 ms |
2392 KB |
Output is correct |
28 |
Correct |
47 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
3932 KB |
Output is correct |
2 |
Correct |
614 ms |
8152 KB |
Output is correct |
3 |
Correct |
1372 ms |
12756 KB |
Output is correct |
4 |
Correct |
1343 ms |
12752 KB |
Output is correct |
5 |
Correct |
1306 ms |
12756 KB |
Output is correct |
6 |
Correct |
1346 ms |
12752 KB |
Output is correct |
7 |
Correct |
1443 ms |
12752 KB |
Output is correct |
8 |
Correct |
1314 ms |
12756 KB |
Output is correct |
9 |
Correct |
1249 ms |
12752 KB |
Output is correct |
10 |
Correct |
2639 ms |
13012 KB |
Output is correct |
11 |
Correct |
2867 ms |
13012 KB |
Output is correct |
12 |
Correct |
3043 ms |
12944 KB |
Output is correct |
13 |
Correct |
2498 ms |
12880 KB |
Output is correct |
14 |
Correct |
2649 ms |
12884 KB |
Output is correct |
15 |
Correct |
2774 ms |
12928 KB |
Output is correct |
16 |
Correct |
2360 ms |
12756 KB |
Output is correct |
17 |
Correct |
2123 ms |
12756 KB |
Output is correct |
18 |
Correct |
2263 ms |
12856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
6 ms |
956 KB |
Output is correct |
5 |
Correct |
6 ms |
860 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
6 ms |
744 KB |
Output is correct |
8 |
Correct |
5 ms |
968 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
4 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
968 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
960 KB |
Output is correct |
18 |
Correct |
5 ms |
860 KB |
Output is correct |
19 |
Correct |
36 ms |
2248 KB |
Output is correct |
20 |
Correct |
47 ms |
2396 KB |
Output is correct |
21 |
Correct |
52 ms |
2392 KB |
Output is correct |
22 |
Correct |
47 ms |
2396 KB |
Output is correct |
23 |
Correct |
46 ms |
2396 KB |
Output is correct |
24 |
Correct |
46 ms |
2396 KB |
Output is correct |
25 |
Correct |
46 ms |
2396 KB |
Output is correct |
26 |
Correct |
46 ms |
2392 KB |
Output is correct |
27 |
Correct |
64 ms |
2392 KB |
Output is correct |
28 |
Correct |
47 ms |
2392 KB |
Output is correct |
29 |
Correct |
136 ms |
3932 KB |
Output is correct |
30 |
Correct |
614 ms |
8152 KB |
Output is correct |
31 |
Correct |
1372 ms |
12756 KB |
Output is correct |
32 |
Correct |
1343 ms |
12752 KB |
Output is correct |
33 |
Correct |
1306 ms |
12756 KB |
Output is correct |
34 |
Correct |
1346 ms |
12752 KB |
Output is correct |
35 |
Correct |
1443 ms |
12752 KB |
Output is correct |
36 |
Correct |
1314 ms |
12756 KB |
Output is correct |
37 |
Correct |
1249 ms |
12752 KB |
Output is correct |
38 |
Correct |
2639 ms |
13012 KB |
Output is correct |
39 |
Correct |
2867 ms |
13012 KB |
Output is correct |
40 |
Correct |
3043 ms |
12944 KB |
Output is correct |
41 |
Correct |
2498 ms |
12880 KB |
Output is correct |
42 |
Correct |
2649 ms |
12884 KB |
Output is correct |
43 |
Correct |
2774 ms |
12928 KB |
Output is correct |
44 |
Correct |
2360 ms |
12756 KB |
Output is correct |
45 |
Correct |
2123 ms |
12756 KB |
Output is correct |
46 |
Correct |
2263 ms |
12856 KB |
Output is correct |
47 |
Execution timed out |
9031 ms |
40268 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |