# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
885530 |
2023-12-10T02:21:27 Z |
Requiem |
Deda (COCI17_deda) |
C++17 |
|
83 ms |
11096 KB |
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME ""
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
int n,m;
const int MAXN = 2e5 + 9;
int st[MAXN<<2];
void update(int node,int l,int r,int pos,int val){
if (l==r){
st[node] = val;
return;
}
int mid = (l+r)>>1;
if (pos <= mid) update(node<<1,l,mid,pos,val);
else update(node<<1|1,mid+1,r,pos,val);
st[node] = min(st[node<<1], st[node<<1|1]);
}
int get(int node,int l,int r,int u,int v,int y){
int mid = (l+r)>>1;
if (l>=u and r<=v){
if (st[node] > y) return -1;
if (l==r) return l;
else if (st[node<<1] <= y) {
return get(node<<1,l,mid,u,v,y);
}
else if (st[node<<1|1] <= y){
return get(node<<1|1,mid+1,r,u,v,y);
}
else return -1;
}
if (l>v or r<u) return -1;
int g1 = get(node<<1,l,mid,u,v,y);
if (g1 != -1) return g1;
else return get(node<<1|1,mid+1,r,u,v,y);
}
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin>>n>>m;
memset(st,0x3f,sizeof(st));
for(int i=1;i<=m;i++){
char c;
int x,a;
cin>>c>>x>>a;
if (c == 'M'){
update(1,1,n,a,x);
}
else{
cout<<get(1,1,n,a,n,x)<<endl;
}
}
}
Compilation message
deda.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main()
| ^~~~
deda.cpp: In function 'int main()':
deda.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
deda.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
6748 KB |
Output is correct |
4 |
Correct |
79 ms |
11096 KB |
Output is correct |
5 |
Correct |
71 ms |
10576 KB |
Output is correct |
6 |
Correct |
75 ms |
10832 KB |
Output is correct |
7 |
Correct |
83 ms |
10952 KB |
Output is correct |