Submission #871792

#TimeUsernameProblemLanguageResultExecution timeMemory
871792serifefedartarBubble Sort 2 (JOI18_bubblesort2)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "bubblesort2.h" using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 1e9+9; const ll LOGN = 20; const ll MAXN = 1e6 + 100; vector<pair<int,int>> cc; int index(pair<int,int> k) { return upper_bound(cc.begin(), cc.end(), k) - cc.begin(); } int sg[4*MAXN], lazy[4*MAXN]; void push(int k, int a, int b) { if (lazy[k]) { sg[k] += lazy[k]; if (a != b) { lazy[2*k] += lazy[k]; lazy[2*k+1] += lazy[k]; } return ; } } void update(int k, int a, int b, int q_l, int q_r, int val) { push(k, a, b); if (b < q_l || a > q_r) return ; if (q_l <= a && b <= q_r) { lazy[k] += val; push(k, a, b); return ; } update(2*k, a, (a+b)/2, q_l, q_r, val); update(2*k+1, (a+b)/2+1, b, q_l, q_r, val); sg[k] = max(sg[2*k], sg[2*k+1]); } int query(int k, int a, int b, int q_l, int q_r) { push(k, a, b); if (b < q_l || a > q_r) return 0; if (q_l <= a && b <= q_r) return sg[k]; return max(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r)); } int N; void add(pair<int,int> p) { int plc = index(p); update(1, 1, N, plc, plc, 1e7 + p.s); update(1, 1, N, plc + 1, N, -1); } void omit(pair<int,int> p) { int plc = index(p); update(1, 1, N, plc, plc, -1e7 - p.s); update(1, 1, N, plc + 1, N, 1); } vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { int n = A.size(), q = V.size(); for (int i = 0; i < n; i++) cc.push_back({A[i], i}); for (int i = 0; i < q; i++) cc.push_back({V[i], X[i]}); sort(cc.begin(), cc.end()); cc.erase(unique(cc.begin(), cc.end()), cc.end()); N = cc.size(); update(1, 1, N, 1, N, -1e7); for (int i = 0; i < n; i++) add({A[i], i}); vector<int> res; for (int i = 0; i < q; i++) { omit({A[X[i]], X[i]}); add({V[i], X[i]}); A[X[i]] = V[i]; push(1, 1, N); res.push_back(sg[1]); } return res; } 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(); std::vector<int> A(N); for(int i=0;i<N;i++) A[i]=readInt(); std::vector<int> X(Q),V(Q); for(int j=0;j<Q;j++){ X[j]=readInt(); V[j]=readInt(); } std::vector<int> res=countScans(A,X,V); for(int j=0;j<int(res.size());j++) printf("%d\n",res[j]); }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccBn2JV5.o: in function `readInt()':
grader.cpp:(.text+0x0): multiple definition of `readInt()'; /tmp/ccO1ZFS5.o:bubblesort2.cpp:(.text+0x860): first defined here
/usr/bin/ld: /tmp/ccBn2JV5.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccO1ZFS5.o:bubblesort2.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status