Submission #922214

#TimeUsernameProblemLanguageResultExecution timeMemory
922214vjudge1Deda (COCI17_deda)C++17
140 / 140
459 ms6572 KiB
//author : FatihCihan #include <bits/stdc++.h> using namespace std; #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() const int inf = 1e9 + 7; struct SEGT{ vector < int > t; int tree_size; const int identity_element = inf; int merge(int x , int y){ return min(x,y); } void init(int x){ tree_size = x+3; t.assign(2*tree_size , identity_element); } void modify(int p, int value) { // set value at position p for (t[p += tree_size] = value; p > 1; p >>= 1){ t[p>>1] = merge(t[p] , t[p^1]); } } int query(int l, int r) { // sum on interval [l, r] int res = identity_element; for (r+=1 , l += tree_size, r += tree_size; l < r; l >>= 1, r >>= 1) { if (l&1) res = merge(res , t[l++]); if (r&1) res = merge(res , t[--r]); } return res; } } segt; void solve(){ int n,q; cin >> n >> q; segt.init(n); while(q--){ char ty; int x,y; cin >> ty >> x >> y; if(ty == 'M'){ segt.modify(y , x); } else{ int l = y , r = n+1; while(l < r){ int mid = (l + r) >> 1; int q1 = segt.query(l , mid); int q2 = segt.query(mid+1 , r); // cout << l << " " << mid << " " << r << " : " << q1 << " " << q2 << endl; if(q1 <= x){ r = mid; } else { l = mid+1; } } cout << (l == n+1 ? -1 : l) << endl; } } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int testcase = 1;//cin >> testcase; while(testcase--)solve(); cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl; }

Compilation message (stderr)

deda.cpp: In function 'void solve()':
deda.cpp:48:9: warning: unused variable 'q2' [-Wunused-variable]
   48 |     int q2 = segt.query(mid+1 , r);
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...