Submission #929181

# Submission time Handle Problem Language Result Execution time Memory
929181 2024-02-17T21:59:59 Z NourWael Deda (COCI17_deda) C++17
140 / 140
77 ms 17744 KB
#include <bits/stdc++.h>
#define int long long
using namespace std; 
int const mxN = 2e5+5;
int n,q, seg[8*mxN], a[8*mxN];
 
int get ( int node, int l_n, int r_n, int l, int r, int v) {
   if(l>=r_n || r<=l_n || seg[node]>v) return 1e17;
   if(l_n==r_n-1) return l_n;
   int m = (l_n+r_n)/2;
   int ans = get(node*2+1, l_n, m, l, r, v );
   if(ans==1e17) ans = get(node*2+2, m, r_n, l, r, v );
   return ans;
}
 
void update(int node, int l, int r, int x, int v ) {
   if(l==r-1) { seg[node] = v; return; }
   int m = (l+r)/2;
   if(x<m) update(node*2+1, l, m, x, v);
   else update(node*2+2, m, r, x, v);
   seg[node] = min(seg[node*2+1], seg[node*2+2]);
}
int dist[mxN];
 
signed main() {
  
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
 
  cin>>n>>q;
  int pw = (1<<(__lg(n)+1));
  for(int i=0; i<8*mxN; i++) seg[i] = 1e17;
  for(int i=0; i<=n; i++) dist[i] = 1e17;
 
  for(int i=0; i<q; i++) {
   char c; cin>>c;
   if(c=='M') {
       int x,a; cin>>x>>a;
       update(0,0,pw,a,x);
       dist[a] = x;
   }
   else  {
      int rides,b; cin>>rides>>b;
      int ans = get(0,0,pw,b,n+1, rides);
      cout<<(ans==1e17? -1:ans)<<'\n';
      bool f = 1;
      //for(int j=b; j<=n; j++) if(dist[j]<=rides) { cout<<j<<'\n'; f = 0; break;}
        // if(f) cout<<"-1\n";
   }
  }
  return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:47:12: warning: unused variable 'f' [-Wunused-variable]
   47 |       bool f = 1;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14424 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Correct 62 ms 17744 KB Output is correct
5 Correct 74 ms 17488 KB Output is correct
6 Correct 75 ms 17508 KB Output is correct
7 Correct 77 ms 17668 KB Output is correct