Submission #1013522

#TimeUsernameProblemLanguageResultExecution timeMemory
1013522vjudge1Bubble Sort 2 (JOI18_bubblesort2)C++17
60 / 100
9031 ms40268 KiB
// #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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...