Submission #136621

#TimeUsernameProblemLanguageResultExecution timeMemory
136621mariusnicoliDeda (COCI17_deda)C++14
140 / 140
875 ms9080 KiB
#include <iostream> #define INF 1000000001 using namespace std; struct nod { int minim; int poz; }; nod a[3200001]; int sol, psol, n, q, statie, om; char c; void build (int nod, int st, int dr) { if (st == dr) { a[nod].minim = INF; a[nod].poz = st; } else { int mid = (st+dr)/2; build(2*nod, st, mid); build(2*nod+1, mid+1, dr); if (a[2*nod].minim <= a[2*nod+1].minim) a[nod] = a[2*nod]; else a[nod] = a[2*nod+1]; } } int update(int nod, int st, int dr, int poz, int value) { if (st == dr) { a[nod].minim = value; a[nod].poz = st; } else { int mid = (st + dr)/2; if (poz <= mid) update(2*nod, st, mid, poz, value); else update(2*nod+1, mid+1, dr, poz, value); if (a[2*nod].minim <= a[2*nod+1].minim) a[nod] = a[2*nod]; else a[nod] = a[2*nod+1]; } } /// cea mai mica pozitie din intervalul a,b cu valoarea /// mai mica sau egala cu value void query(int nod, int st, int dr, int A, int B, int value) { if (sol != INF) return; if (st == dr && a[nod].minim <= value && sol == INF) { sol = a[nod].minim; psol = a[nod].poz; return; } if (A <= st && dr <= B) { if (a[nod].minim <= value) { int mid = (st+dr)/2; if (a[2*nod].minim <= value) query(2*nod, st, mid, A, B, value); else query(2*nod+1, mid+1, dr, A, B, value); } } else { int mid = (st+dr)/2; if (A <= mid) query(2*nod, st, mid, A, B, value); if (B > mid) query(2*nod+1, mid+1, dr, A, B, value); } } int main () { cin>>n>>q; build(1, 1, n); ///cout<<a[1].poz; for (;q--;) { cin>>c>>statie>>om; if (c == 'M') update(1, 1, n, om, statie); else { sol = INF; query(1, 1, n, om, n, statie); if (sol > statie) cout<<"-1\n"; else cout<<psol<<"\n"; } } return 0; }

Compilation message (stderr)

deda.cpp: In function 'int update(int, int, int, int, int)':
deda.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...