# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
411192 |
2021-05-24T14:52:47 Z |
singh |
Deda (COCI17_deda) |
C++14 |
|
0 ms |
0 KB |
include <bits/stdc++.h>
using namespace std;
const int maxn=2e5;
pair<int,int> tv[4*maxn];
int arr[maxn];
int dist[maxn];
pair<int,int> combine(pair<int,int> a, pair<int,int> b)
{
if(a.first>b.first)
return b;
else if(b.first>a.first)
return a;
}
void build(int v,int tl,int tr)
{
if(tl==tr)
tv[v]={dist[arr[tl]],arr[tl]};
else
{
int mid=(tl+tr)/2;
build(v*2,tl,mid);
build(v*2+1,mid+1,tr);
tv[v]=combine(tv[v*2],tv[v*2+1]);
}
}
pair<int,int> get_first(int v, int lv, int rv, int l, int r, int x) {
if(lv > r || rv < l) return {-1,-1};
if(l <= lv && rv <= r) {
if(tv[v].first> x) return {-1,-1};
while(lv != rv) {
int mid = lv + (rv-lv)/2;
if(tv[2*v].first <= x) {
v = 2*v;
rv = mid;
}else {
v = 2*v+1;
lv = mid+1;
}
}
return {arr[lv],tv[lv].first};
}
int mid = lv + (rv-lv)/2;
pair<int,int> rs = get_first(2*v, lv, mid, l, r, x);
if(rs.first != -1) return rs;
return get_first(2*v+1, mid+1, rv, l ,r, x);
}
void update(int v, int tl, int tr, int pos,int new_val) {
if (tl == tr) {
tv[v]={new_val,arr[tl]};
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v*2, tl, tm, pos, new_val);
else
update(v*2+1, tm+1, tr, pos, new_val);
tv[v] = combine(tv[v*2], tv[v*2+1]);
}
}
int main()
{
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
arr[i]=i;
dist[i]=INT_MAX;
}
build(1,1,n);
while(q--)
{
int b,c;
char a;
cin>>a>>b>>c;
if(a=='M')
update(1,1,n,c,b);
else{
pair<int,int> r=get_first(1,1,n,c,n,b);
cout<<r.first<<endl;
}
}
}
Compilation message
deda.cpp:1:1: error: 'include' does not name a type
1 | include <bits/stdc++.h>
| ^~~~~~~
deda.cpp:4:1: error: 'pair' does not name a type
4 | pair<int,int> tv[4*maxn];
| ^~~~
deda.cpp:7:2: error: 'pair' does not name a type
7 | pair<int,int> combine(pair<int,int> a, pair<int,int> b)
| ^~~~
deda.cpp: In function 'void build(int, int, int)':
deda.cpp:19:3: error: 'tv' was not declared in this scope; did you mean 'v'?
19 | tv[v]={dist[arr[tl]],arr[tl]};
| ^~
| v
deda.cpp:26:7: error: 'tv' was not declared in this scope; did you mean 'v'?
26 | tv[v]=combine(tv[v*2],tv[v*2+1]);
| ^~
| v
deda.cpp:26:13: error: 'combine' was not declared in this scope
26 | tv[v]=combine(tv[v*2],tv[v*2+1]);
| ^~~~~~~
deda.cpp: At global scope:
deda.cpp:30:1: error: 'pair' does not name a type
30 | pair<int,int> get_first(int v, int lv, int rv, int l, int r, int x) {
| ^~~~
deda.cpp: In function 'void update(int, int, int, int, int)':
deda.cpp:55:9: error: 'tv' was not declared in this scope; did you mean 'v'?
55 | tv[v]={new_val,arr[tl]};
| ^~
| v
deda.cpp:62:9: error: 'tv' was not declared in this scope; did you mean 'tm'?
62 | tv[v] = combine(tv[v*2], tv[v*2+1]);
| ^~
| tm
deda.cpp:62:17: error: 'combine' was not declared in this scope
62 | tv[v] = combine(tv[v*2], tv[v*2+1]);
| ^~~~~~~
deda.cpp: In function 'int main()':
deda.cpp:69:3: error: 'cin' was not declared in this scope
69 | cin>>n>>q;
| ^~~
deda.cpp:73:14: error: 'INT_MAX' was not declared in this scope
73 | dist[i]=INT_MAX;
| ^~~~~~~
deda.cpp:1:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
+++ |+#include <climits>
1 | include <bits/stdc++.h>
deda.cpp:85:7: error: 'pair' was not declared in this scope
85 | pair<int,int> r=get_first(1,1,n,c,n,b);
| ^~~~
deda.cpp:85:12: error: expected primary-expression before 'int'
85 | pair<int,int> r=get_first(1,1,n,c,n,b);
| ^~~
deda.cpp:86:7: error: 'cout' was not declared in this scope
86 | cout<<r.first<<endl;
| ^~~~
deda.cpp:86:13: error: 'r' was not declared in this scope
86 | cout<<r.first<<endl;
| ^
deda.cpp:86:22: error: 'endl' was not declared in this scope
86 | cout<<r.first<<endl;
| ^~~~