Submission #673794

#TimeUsernameProblemLanguageResultExecution timeMemory
673794smartmonkyWeighting stones (IZhO11_stones)C++14
100 / 100
181 ms4420 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} const int N = 100001; pair <int,int> t[N * 4]; int add[N * 4], mn; int n; void push(int v, int l, int r){ if(l != r && add[v]){ add[v * 2] += add[v]; add[v * 2 + 1] += add[v]; } t[v].ff += add[v]; t[v].ss += add[v]; add[v] = 0; } void update(int l, int r,int val, int v = 1, int tl = 1, int tr = n){ push(v, tl, tr); if(tl > r || tr < l) return; if(tl >= l && tr <= r){ add[v] += val; push(v, tl, tr); return; } int mid = (tl + tr) >> 1; update(l, r, val, v * 2, tl, mid); update(l, r, val, v * 2 + 1, mid + 1, tr); t[v].ff = min(t[v * 2].ff, t[v * 2 + 1].ff); t[v].ss = max(t[v * 2].ss, t[v * 2 + 1].ss); } pair <int,int> get(int l, int r, int v = 1, int tl = 1, int tr = n){ push(v, tl, tr); if(tl > r || tr < l) return {1e9, -1e9}; if(tl >= l && tr <= r){ return t[v]; } int mid = (tl + tr) >> 1; pair <int,int> left = get(l, r, v * 2, tl, mid); pair <int,int> right = get(l, r, v * 2 + 1, mid + 1, tr); return {min(left.ff, right.ff), max(left.ss, right.ss)}; } main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ int r, s; cin >> r >> s; int dob = 1; if(s == 2) dob = -1; update(1, r, dob); pair <int,int> res = get(1, n); if(res.ss <= 0){ cout << "<"; }else if(res.ff >= 0){ cout << ">"; }else cout <<"?"; cout << endl; } }

Compilation message (stderr)

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