Submission #309235

#TimeUsernameProblemLanguageResultExecution timeMemory
309235nikatamlianiInterval Collection (CCO20_day2problem2)C++14
3 / 25
7066 ms63996 KiB
#include <bits/stdc++.h> #define x first #define y second using namespace std; const int N = 1e6 + 5, oo = 1e9; multiset < int > ms[N]; int tree[4 * N]; void update(int l, int r, int x, int val, int p) { if(l > x || r < x) return; if(l == r) { tree[p] = val; } else { int m = l + r >> 1; update(l, m, x, val, p << 1); update(m + 1, r, x, val, p << 1 | 1); tree[p] = min(tree[p << 1], tree[p << 1 | 1]); } } int query(int l, int r, int L, int R, int p) { if(L > r || l > R) return oo; if(L <= l && R >= r) return tree[p]; int m = l + r >> 1; return min(query(l, m, L, R, p << 1), query(m + 1, r, L, R, p << 1 | 1)); } int main() { for(int i = 0; i < 4 * N; ++i) tree[i] = oo; 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[l].erase(ms[l].find(r)); int val = oo; if(!ms[l].empty()) { val = *ms[l].begin(); } update(1, N - 1, l, val, 1); } else { m.insert({l, r}); ms[l].insert(r); update(1, N - 1, l, *ms[l].begin(), 1); } int maxL = -1, minR = 1e9; for(auto [l, r] : m) { maxL = max(maxL, l); minR = min(minR, r); } if(minR <= maxL) { int best = 1e9; for(auto [l, r] : m) { best = min(best, query(1, N - 1, r, N - 1, 1) - l); } cout << best << '\n'; } else { int ansL = -1, ansR = 1e9; for(auto [l, r] : m) { if(l == maxL) { ansR = min(ansR, r); } if(r == minR) { ansL = max(ansL, l); } } cout << ansR - ansL << '\n'; } } }

Compilation message (stderr)

Main.cpp: In function 'void update(int, int, int, int, int)':
Main.cpp:13:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |         int m = l + r >> 1;
      |                 ~~^~~
Main.cpp: In function 'int query(int, int, int, int, int)':
Main.cpp:22:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     int m = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:48:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         for(auto [l, r] : m) {
      |                  ^
Main.cpp:54:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |             for(auto [l, r] : m) {
      |                      ^
Main.cpp:60:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |             for(auto [l, r] : m) {
      |                      ^
#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...