Submission #882183

#TimeUsernameProblemLanguageResultExecution timeMemory
882183Mr_HusanboyWeighting stones (IZhO11_stones)C++17
100 / 100
42 ms7716 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debugger.cpp" #else #define debug(...) #endif template<class T> int len(T &a){ return a.size(); } using ll = long long; using pii = pair<int,int>; #define all(a) (a).begin(), (a).end() #define ff first #define ss second string fileio = ""; mt19937 mt(time(nullptr)); const int mod = 1e9 + 7; const int inf = 1e9; const ll infl = 1e18; const int maxn = 1e5 + 1; struct SegmentTree{ //To change struct Node{ //defaults int mn = 0, mx = 0; int add = 0; bool marked = false; void apply(int x){ mx += x; mn += x; add += x; marked = true; } }; void push(int x){ if(t[x].marked){ t[x << 1].apply(t[x].add); t[x << 1 | 1].apply(t[x].add); t[x].add = 0; t[x].marked = false; } } Node merge(Node a, Node b){ return {min(a.mn, b.mn), max(a.mx, b.mx), 0, false}; } Node neutral = {inf, -inf, 0, false}; vector<Node> t; int n; //construction void init(int _n){ n = _n; t.resize(4 * n); } void upd(int x, int lx, int rx, int l, int r, int val){ if(rx < l || r < lx) return; if(l <= lx && rx <= r){ t[x].apply(val); return; } push(x); int mx = (lx + rx) >> 1; upd(x << 1, lx, mx, l, r, val); upd(x << 1 | 1, mx + 1, rx, l, r, val); t[x] = merge(t[x << 1], t[x << 1 | 1]); } Node get(int x, int lx, int rx, int l, int r){ if(rx < l || r < lx){ return neutral; } if(l <= lx && rx <= r){ return t[x]; } push(x); int mx = (lx + rx) >> 1; return merge(get(x << 1, lx, mx, l, r), get(x << 1 | 1, mx + 1, rx, l, r)); } // lessen void upd(int l, int r, int val){ upd(1, 0, n - 1, l, r, val); } Node get(int l, int r){ return get(1, 0, n - 1, l, r); } }; void solve(){ int n; cin >> n; SegmentTree t; t.init(n); for(int _ = 0; _ < n; _ ++){ int l, r; cin >> l >> r; l --; t.upd(0, l, (r == 1 ? -1 : 1)); auto k = t.get(0, n - 1); cout << (k.mx <= 0 ? ">" : k.mn >= 0 ? "<" : "?") << '\n'; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); auto start = chrono::high_resolution_clock::now(); #ifndef LOCAL if(fileio.size()){ freopen((fileio + ".in").c_str(), "r", stdin); freopen((fileio + ".out").c_str(), "w", stdout); } #endif int testcases = 1; #ifdef Tests cin >> testcases; #endif while(testcases --){ solve(); cout << '\n'; #ifdef LOCAL cout << "_________________________" << endl; #endif } #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif return 0; }

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:126:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  126 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
stones.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...