# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535487 | LouayFarah | Deda (COCI17_deda) | C++14 | 107 ms | 8888 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"
using namespace std;
#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const long long MOD = 1e9+7;
const long long INF = 1e18;
int nx[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int ny[8] = {1, -1, 0, 0, 1, 1, -1, -1};
ll my_rand(ll l, ll r)
{
srand(chrono::steady_clock::now().time_since_epoch().count());
ll len = r-l+1;
ll a = rand()%len;
ll b = rand()%len;
ll res = ((a%len) + (b%len))%len;
if(res<l)
res +=l;
return res;
}
struct segtree
{
ll size;
ll INIT;
vector<ll> values;
void init(ll n)
{
size = 1;
while(size<n)
size*=2;
INIT = 1e16;
values.assign(2*size, INIT);
}
ll combine(ll a, ll b)
{
return min(a, b);
}
void change(ll i, ll v, ll lx, ll rx, ll x)
{
if(rx-lx<=1)
{
values[x] = v;
return;
}
ll mid = (lx+rx)/2;
if(i<mid)
change(i, v, lx, mid, 2*x+1);
else
change(i, v, mid, rx, 2*x+2);
values[x] = combine(values[2*x+1], values[2*x+2]);
}
ll op(ll l, ll y, ll lx, ll rx, ll x)
{
if(values[x]>y)
return -1;
if(rx<=l)
return -1;
if(rx-lx<=1)
{
return lx;
}
ll mid = (lx+rx)/2;
ll res = op(l, y, lx, mid, 2*x+1);
if(res==-1)
res = op(l, y, mid, rx, 2*x+2);
return res;
}
void change(ll i, ll v)
{
change(i, v, 0, size, 0);
}
ll op(ll l, ll y)
{
return op(l, y, 0, size, 0);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, q;
cin >> n >> q;
segtree tree;
tree.init(n+1);
while(q--)
{
char c;
cin >> c;
if(c=='M')
{
ll x, a;
cin >> x >> a;
tree.change(a, x);
}
else
{
ll y, b;
cin >> y >> b;
ll res = tree.op(b, y);
//if left<=y
//else if right<=y
//else return -1
cout << res << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |