제출 #311136

#제출 시각아이디문제언어결과실행 시간메모리
311136nikatamlianiInterval Collection (CCO20_day2problem2)C++14
0 / 25
114 ms34552 KiB
#include <bits/stdc++.h> #define x first #define y second using namespace std; const int N = 1e5 + 5, oo = 1e9, LEFT = 0, RIGHT = 1; multiset < int > ms[2][N], L, R; struct node{ int maxL = -oo, minR = oo, best = minR - maxL; }tree[N * 4]; node merge(node L, node R) { node x; x.maxL = max(L.maxL, R.maxL); x.minR = min(L.minR, R.minR); x.best = min({L.best, R.best, R.minR - L.maxL}); return x; } void update(int l, int r, int x, int val, int p, int TYPE) { if(l > x || r < x) return; if(l == r) { if(TYPE == LEFT) { tree[p].maxL = val; } else { tree[p].minR = val; } tree[p].best = tree[p].minR - tree[p].maxL; } else { int m = l + r >> 1; update(l, m, x, val, p << 1, TYPE); update(m + 1, r, x, val, p << 1 | 1, TYPE); tree[p] = merge(tree[p << 1], tree[p << 1 | 1]); } } int main() { int q; cin >> q; multiset < pair < int, int > > m; for(int i = 1; i <= q; ++i) { int l, r; char t; cin >> t >> l >> r; if(t == 'R') { m.erase(m.find({l, r})); ms[0][l].erase(ms[0][l].find(r)); ms[1][r].erase(ms[1][r].find(l)); L.erase(L.find(l)); R.erase(R.find(r)); int lf = -oo, rg = oo; if(!ms[0][l].empty()) rg = *ms[0][l].begin(); if(!ms[1][r].empty()) lf = *ms[1][r].rbegin(); update(1, N - 1, l, rg, 1, RIGHT); update(1, N - 1, r, lf, 1, LEFT); } else { m.insert({l, r}); ms[0][l].insert(r); ms[1][r].insert(l); L.insert(l); R.insert(r); int lf, rg; if(!ms[0][l].empty()) rg = *ms[0][l].begin(); if(!ms[1][r].empty()) lf = *ms[1][r].rbegin(); update(1, N - 1, l, rg, 1, RIGHT); update(1, N - 1, r, lf, 1, LEFT); } int maxL = *L.rbegin(), minR = *R.begin(); // for(auto [l, r] : m) { // maxL = max(maxL, l); // minR = min(minR, r); // } if(minR <= maxL) { cout << tree[1].best << '\n'; } else { int ansL = -1, ansR = 1e9; ansR = *ms[0][maxL].begin(); ansL = *ms[1][minR].rbegin(); // for(auto [l, r] : m) { // if(l == maxL) { // ansR = min(ansR, r); // } // if(r == minR) { // ansL = max(ansL, l); // } // } cout << ansR - ansL << '\n'; } } }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void update(int, int, int, int, int, int)':
Main.cpp:27:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |         int m = l + r >> 1;
      |                 ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:61:19: warning: 'rg' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |             update(1, N - 1, l, rg, 1, RIGHT);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:62:19: warning: 'lf' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |             update(1, N - 1, r, lf, 1, LEFT);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...