#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mid (l+r)/2
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1000000007;
const ll inf=1e18*4;
const ld pai=acos(-1);
int n,q;
int tree[800009];
void build(int node,int l,int r){
if(l==r){
tree[node]=1e9*2;//change it to inf
return;
}
build(node*2,l,mid);
build(node*2+1,mid+1,r);
tree[node]=min(tree[node*2],tree[node*2+1]);
}
int query(int node,int l,int r,int s,int e){
if(s<=l && e>=r)return tree[node];
if(s<=mid && e>=mid+1)return min(query(node*2,l,mid,s,e),query(node*2+1,mid+1,r,s,e));
else if(s<=mid)return query(node*2,l,mid,s,e);
else return query(node*2+1,mid+1,r,s,e);
}
void upd(int node,int l,int r,int k,int val){
if(l==r){
tree[node]=val;
return;
}
if(k<=mid)upd(node*2,l,mid,k,val);
else upd(node*2+1,mid+1,r,k,val);
tree[node]=min(tree[node*2],tree[node*2+1]);
}
int bin(int L,int x){
int l=L-1,r=n;
while(r-l>1){
int m=(l+r)/2;
if(query(1,0,n-1,L,m)<=x)r=m;
else l=m;
}
if(r==n)return -1;
return r+1;
}
int main(){
scanf("%d%d",&n,&q);
build(1,0,n-1);
while(q--){
char t;cin>>t;
if(t=='M'){
int id,val;
scanf("%d%d",&val,&id);
id--;
upd(1,0,n-1,id,val);
}
else{
int l,x;
scanf("%d%d",&l,&x);
l--;
printf("%d\n",bin(l,x));
}
}
}
Compilation message
deda.cpp: In function 'int main()':
deda.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&q);
~~~~~^~~~~~~~~~~~~~
deda.cpp:71:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&val,&id);
~~~~~^~~~~~~~~~~~~~~~~
deda.cpp:77:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&l,&x);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
3 |
Incorrect |
18 ms |
376 KB |
Output isn't correct |
4 |
Incorrect |
705 ms |
3944 KB |
Output isn't correct |
5 |
Incorrect |
516 ms |
1784 KB |
Output isn't correct |
6 |
Incorrect |
566 ms |
2868 KB |
Output isn't correct |
7 |
Incorrect |
596 ms |
3160 KB |
Output isn't correct |