Submission #672947

#TimeUsernameProblemLanguageResultExecution timeMemory
672947Alihan_8Weighting stones (IZhO11_stones)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long const int N = 1e5+1; struct SegTree{ vector <array<int,2>> T; vector <int> lazy; const int inf = numeric_limits <int>::max(); void re_size(int n){ T.resize(n*4+1); lazy.resize(n*4+1); } void push(int v, int l, int r){ if ( !lazy[v] ) return; if ( l != r ){ lazy[v*2] += lazy[v]; lazy[v*2+1] += lazy[v]; } T[v][0] += lazy[v]*(r-l+1); T[v][1] += lazy[v]*(r-l+1); lazy[v] = 0; } void upd(int v, int l, int r, int tl, int tr, int val){ push(v, l, r); if ( l > tr or tl > r ) return; if ( tl <= l and tr >= r ){ lazy[v] += val; push(v, l, r); return; } int md = (l+r)>>1; upd(v*2, l, md, tl, tr, val), upd(v*2+1, md+1, r, tl, tr, val); T[v][0] = min(T[v*2][0], T[v*2+1][0]); T[v][1] = max(T[v*2][1], T[v*2+1][1]); } int get_min(int v, int l, int r, int tl, int tr){ push(v, l, r); if ( l > tr or tl > r ) return inf; if ( tl <= l and tr >= r ) return T[v][0]; int md = (l+r)>>1; return min(get_min(v*2, l, md, tl, tr), get_min(v*2+1, md+1, r, tl, tr)); } int get_max(int v, int l, int r, int tl, int tr){ push(v, l, r); if ( l > tr or tl > r ) return -inf; if ( tl <= l and tr >= r ) return T[v][1]; int md = (l+r)>>1; return max(get_max(v*2, l, md, tl, tr), get_max(v*2+1, md+1, r, tl, tr)); } } T; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int q, n; cin >> q; T.re_size(q+1); n = q; auto ins = [&](int x, int s){ int sign = 1; if ( s == 2 ) sign *= -1; T.upd(1, 1, n, 1, x, sign); }; auto get = [&](int it){ if ( it == 0 ) return T.get_min(1, 1, n, 1, n); return T.get_max(1, 1, n, 1, n); }; while ( q-- ){ int x, s; cin >> x >> s; ins(x, s); if ( min(get(0), get(1)) >= 0 ) cout << ">\n"; else if ( max(get(0), get(1)) <= 0 ) cout << "<\n"; else cout << "?\n"; } cout << '\n'; }

Compilation message (stderr)

stones.cpp: In function 'void IO(std::string)':
stones.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...