Submission #929137

#TimeUsernameProblemLanguageResultExecution timeMemory
929137sondos225Deda (COCI17_deda)C++17
60 / 140
8 ms16476 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); #define pb push_back #define yes "YES" #define no "NO" #define bigg INT_MAX #define debug(x) cout<<(#x)<<" = " <<x<<endl; #define all(x) x.begin(),x.end() #define sz size() #define nn '\n' #define mms(x,y) memset(x,y,sizeof(x)) #define forr(i,j,n) for (int i=j; i<n; i++) #define forn(i,j,n) for (int i=j; i>n; i--) #define fi first #define se second #define la "LA" #define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i]; #define pii pair<int,int> #define tii tuple<int,int,int> pii seg[500000]; void edit(int ll, int rr, int i, int idx, int val) { if (ll==rr && ll==idx) { if (val<seg[i].fi) { seg[i]={val,idx}; } else if (val==seg[i].fi) seg[i].se=min(idx,seg[i].se); return; } int m=(ll+rr)/2; if (idx<=m) { edit(ll,m,(2*i)+1,idx, val); } else edit(m+1,rr,(2*i)+2,idx,val); seg[i]=min(seg[(2*i)+1],seg[(2*i)+2]); return; } int query(int ll, int rr, int i, int l, int val) {int m=(ll+rr)/2; int mn=seg[i].fi; int idx=seg[i].se; if (mn<=val && idx>=l) return min(idx,min(query(m+1,rr,(i*2)+2,l,val),query(ll,m,(i*2)+1,l,val))); if (mn>val) return bigg; if (l>m) return query(m+1,rr,(i*2)+2,l,val); return min(query(m+1,rr,(i*2)+2,l,val),query(ll,m,(i*2)+1,l,val)); } signed main() { // #ifndef LOCAL // freopen("helpcross.in","r",stdin); // freopen("helpcross.out","w", stdout); // #endif fast forr(i,0,500000) seg[i]={bigg,0}; int n,q; cin>>n >>q; while(q--) { char w; int x,y; cin>>w >>x >>y; if (w=='M') { edit(1,n,0,y,x); } else { int ans=query(1,n,0,y,x); if (ans==bigg) ans=-1; cout<<ans<<nn; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...