Submission #851755

#TimeUsernameProblemLanguageResultExecution timeMemory
851755vjudge1Bubble Sort 2 (JOI18_bubblesort2)C++17
22 / 100
6291 ms68768 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) int pr=23, s_p=1<<pr, e_p=(1<<(pr+1))-1; int n; vector<int>S_sum; void pre(){ S_sum.clear(); S_sum.resize(1<<(pr+1)); } void update(int ind, int c){ S_sum[ind]+=c; while(ind/=2) S_sum[ind]+=c; } int get(int id, int u, int v, int l, int r){ if(l>v || r<u) return 0; if(l>=u && r<=v) return S_sum[id]; int md=(l+r)/2; return get(id*2, u, v, l, md)+get(id*2+1, u, v, md+1, r); } vector<int> countScans(vector<int>A, vector<int>X, vector<int>V){ vector<int>S, All, Cur(A.size()); n=A.size(); int q=X.size(); for(int i=0;i<n;i++){ All.push_back(A[i]); } for(int i=0;i<q;i++){ All.push_back(V[i]); } sort(all(All)); int cur=1; map<int, int>mp; for(int i=0;i<All.size();i++){ if(i==All.size()-1 || All[i]!=All[i+1]) mp[All[i]]=cur++; } for(int i=0;i<n;i++){ A[i]=mp[A[i]]; } pre(); for(int i=0;i<n;i++){ int cur=get(1, s_p+A[i]+1, e_p, s_p, e_p); Cur[i]=cur; update(s_p+A[i], 1); } for(int i=0;i<n;i++){ update(s_p+A[i], -1); } for(int k=0;k<q;k++){ int ind=X[k], val=V[k]; bool larger=(val>A[ind]); int mx=0, inc=0; for(int i=0;i<ind;i++){ if(!larger){ inc+=(A[i]<=A[ind] && A[i]>val); } else{ inc-=(A[i]>A[ind] && A[i]<=val); } } Cur[ind]+=inc; for(int i=ind+1;i<n;i++){ if(!larger){ Cur[i]-=(A[i]<A[ind] && A[i]>=val); } else{ Cur[i]+=(A[i]<val && A[i]>=A[ind]); } } A[ind]=val; for(int i=0;i<n;i++){ mx=max(mx, Cur[i]); } S.push_back(mx); } return S; } //int main(){ // ios_base::sync_with_stdio(0);cin.tie(0); // int n, q; // cin>>n>>q; // vector<int>A(n), X(q), V(q); // for(int i=0;i<n;i++){ // cin>>A[i]; // } // for(int j=0;j<q;j++){ // cin>>X[j]>>V[j]; // } // vector<int>Ans=countScans(A, X, V); // for(int i=0;i<q;i++){ // cout<<Ans[i]<<endl; // } //}

Compilation message (stderr)

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<All.size();i++){
      |                 ~^~~~~~~~~~~
bubblesort2.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if(i==All.size()-1 || All[i]!=All[i+1])
      |            ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...