# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79941 | luckyboy | Deda (COCI17_deda) | C++14 | 193 ms | 13960 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#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 pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 200005
#define maxm 500005
#define pii pair <int,int>
#define Task "Deda"
using namespace std;
int n,q,t[maxn << 2],x,y;
char c;
void Update(int l,int r,int id,int x,int val)
{
t[id] = min(t[id],val);
if (l == r) return;
int mid = (l+r) >> 1;
if (mid >= x) Update(l,mid,2*id,x,val);
else Update(mid+1,r,2*id+1,x,val);
}
int Find(int l,int r,int id,int x,int val)
{
if (r < x) return 0;
if (l == r) return (t[id] <= val ? l : 0);
if (x <= l && t[id] > val) return 0;
int mid = (l+r) >> 1;
int temp = Find(l,mid,2*id,x,val);
if (temp) return temp;
return Find(mid+1,r,2*id+1,x,val);
}
int main()
{
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
scanf("%d%d",&n,&q);
FOR(i,1,n << 2) t[i] = maxc;
while (q--)
{
scanf("%c%c%d%d",&c,&c,&x,&y);
if (c == 'M') Update(1,n,1,y,x);
else
{
int ans = Find(1,n,1,y,x);
if (!ans) ans = -1;
printf("%d\n",ans);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |