Submission #884133

#TimeUsernameProblemLanguageResultExecution timeMemory
884133vjudge1Bubble Sort 2 (JOI18_bubblesort2)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include <bubblesort2.h> using namespace std; const int N = 5e5; vector <int> a; vector <int> v2; vector <int> x; class fenwick{ int fen[N]; int n; public: void init(int sz){ n = sz; for(int i = 0;i < n;i++)fen[i] = 0; } void add(int pos){ for(int i = pos;i < n;i|=(i + 1)){ fen[i]++; } } int get(int pos){ int r = 0; for(int i = pos;i >= 0;i&=(i + 1),i--){ r+=fen[i]; } return r; } }; int fen2[N][M]; int n,q; void add(int x,int y,int nr){ //cout<<"add:"<<x<<' '<<y<<' '<<nr<<'\n'; for(int i = x;i < n;i|=(i + 1)){ for(int j = y;j >= 0;j&=(j + 1),j--){ fen2[i][j]+=nr; } } } int get(int x,int y){ //cout<<"get:"<<x<<' '<<y<<' '; int r = 0; for(int i = x;i >= 0;i&=(i + 1),i--){ for(int j = y;j < M;j|=(j + 1)){ r+=fen2[i][j]; } } //cout<<r<<'\n'; return r; } set <int> last[M]; int p[N]; fenwick fen; int cnt = 0; vector <int> countScans(vector <int> v,vector <int> q1,vector <int> q2){ n = v.size(); q = q1.size(); bool ok = 0; for(int i = 0;i < q;i++){ q2[i]--; } for(int i = 0;i < n;i++){ v[i]--; if(v[i] >= 100)ok = 1; if(v[i] < 100)last[v[i]].insert(i); } vector<int>ans; for(int i = 0;i < q;i++){ v[q1[i]] = q2[i]; fen.init(n); int ans2 = 0; for(int j = 0;j < n;j++)p[j] = j; sort(p,p + n,[&](int a,int b){ if(v[a] == v[b])return a > b; return v[a] > v[b]; }); for(int i = 0;i < n;i++){ ans2 = max(ans2,fen.get(p[i])); fen.add(p[i]); } ans.push_back(ans2); //cout<<ans2<<' '; } return ans; } /*int main(){ int n,q; cin>>n>>q; for(int i = 0;i < n;i++){ int b; cin>>b; a.push_back(b); } for(int i= 0;i < q;i++){ int b,c; cin>>b>>c; v2.push_back(c); x.push_back(b); } countScans(a,x,v2); return 0; }*/ /** 4 2 1 2 3 4 0 3 2 1 **/

Compilation message (stderr)

bubblesort2.cpp:29:13: error: 'M' was not declared in this scope
   29 | int fen2[N][M];
      |             ^
bubblesort2.cpp: In function 'void add(int, int, int)':
bubblesort2.cpp:35:13: error: 'fen2' was not declared in this scope
   35 |             fen2[i][j]+=nr;
      |             ^~~~
bubblesort2.cpp: In function 'int get(int, int)':
bubblesort2.cpp:43:27: error: 'M' was not declared in this scope
   43 |         for(int j = y;j < M;j|=(j + 1)){
      |                           ^
bubblesort2.cpp:44:16: error: 'fen2' was not declared in this scope
   44 |             r+=fen2[i][j];
      |                ^~~~
bubblesort2.cpp: At global scope:
bubblesort2.cpp:50:16: error: 'M' was not declared in this scope
   50 | set <int> last[M];
      |                ^
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:64:23: error: 'last' was not declared in this scope
   64 |         if(v[i] < 100)last[v[i]].insert(i);
      |                       ^~~~