# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
222941 |
2020-04-14T11:43:11 Z |
ngot23 |
Deda (COCI17_deda) |
C++11 |
|
1000 ms |
5368 KB |
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int t[N*4], n, Q, ID[N*4];
void build(int l, int r, int id) {
if(l==r) {
ID[l] = id;
t[id] = 1e9 + 1;
return;
}
int mid=(r+l)>>1;
build(l, mid, id*2);
build(mid+1, r, id*2+1);
}
void update(int u, int val) {
u=ID[u];
t[u]=val;
while(u/2!=0) {
int id=u/2;
t[id]=min(t[u], t[u^1]);
u = id;
}
}
int get(int l, int r, int id, int u, int v) {
if(v<l || r<u) return int(1e9+1);
if(u<=l && r<=v) return t[id];
int mid=(r+l)>>1;
return min(get(l, mid, id*2, u, v), get(mid+1, r, id*2+1, u, v));
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
cin >> n >> Q;
build(1, n, 1);
for(int i=1 ; i<=Q ; ++i) {
int c, d; char x;
cin >> x >> c >> d;
if(x=='M') {
update(d, c);
} else {
int l=d-1, r=n+1;
while(r-l>1) {
int mid=r+l >> 1;
if(get(1, n, 1, d, mid) <= c) r=mid;
else l=mid;
}
if(r==n+1) r=-1;
cout << r << '\n';
}
}
return 0;
}
Compilation message
deda.cpp: In function 'int main()':
deda.cpp:50:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=r+l >> 1;
~^~
deda.cpp:37:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
384 KB |
Output isn't correct |
4 |
Execution timed out |
1078 ms |
5128 KB |
Time limit exceeded |
5 |
Incorrect |
672 ms |
3284 KB |
Output isn't correct |
6 |
Incorrect |
819 ms |
5368 KB |
Output isn't correct |
7 |
Incorrect |
927 ms |
4996 KB |
Output isn't correct |