#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<iomanip>
#include<math.h>
#include<queue>
#include<cmath>
#include<complex.h>
#include<deque>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
# define pii pair<int,int>
#define sec second
#define ft first
#define mp make_pair
#define fio ios_base::sync_with_stdio(false)
int n, q ;
int a[100009];
int t[400009];
void update(int v , int l , int r , int pos , int val )
{
if(l == r)
{
t[v] = val ;
return ;
}
int mid = (l+r)/2;
if(mid < pos) update(2*v+1,mid+1,r,pos,val);
else update(2*v,l,mid,pos,val);
t[v] = min(t[2*v],t[2*v+1]);
}
int get(int v , int l , int r , int tl , int tr)
{
//cout << l << " " << r << tl << " " << tr << "\n";
if(tl > tr) return 1e9+1 ;
if(l == tl and r == tr) return t[v];
int mid = (l+r)/2;
return min(get(2*v,l,mid,tl,min(mid,tr)),get(2*v+1,mid+1,r,max(tl,mid+1),tr));
}
int main()
{
cin >> n >> q ;
for(int i = 1 ; i <= 4*n ; i++) t[i] = 1e9+1 ;
while(q--)
{
char c ;
int x , y ;
cin >> c >> x >> y;
if(c == 'M') update(1,1,n,y,x);
else
{
int l = y , r = n ;
//cout << l << " " << r << "\n";
while(l < r)
{
//cout << l << " " << r << "\n";
int mid = (l+r)/2;
if(get(1,1,n,y,mid) <= x) r = mid;
else l = mid+1 ;
}
if(get(1,1,n,y,r) <= x or y > n) cout <<r << "\n";
else cout << "-1\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
17 ms |
204 KB |
Output is correct |
4 |
Runtime error |
4 ms |
4300 KB |
Execution killed with signal 11 |
5 |
Execution timed out |
1096 ms |
2664 KB |
Time limit exceeded |
6 |
Runtime error |
4 ms |
4300 KB |
Execution killed with signal 11 |
7 |
Runtime error |
4 ms |
4300 KB |
Execution killed with signal 11 |