# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
962420 |
2024-04-13T13:39:18 Z |
hariaakas646 |
Deda (COCI17_deda) |
C++14 |
|
80 ms |
8016 KB |
#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
void fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
template <class T>
struct SegTree
{
int size = 1, n;
vector<T> segtree;
vector<T> vec;
T def; // Assign a value
void init(int l, T defv)
{
n = l;
def = defv;
while (size < n)
size *= 2;
segtree.assign(2 * size, def);
vec.assign(size, def);
}
T operation(T x, T y)
{
return min(x, y); // Any required operation
}
void recalculate(int x)
{
segtree[x] = operation(segtree[2 * x + 1], segtree[2 * x + 2]);
}
void build(int x, int l, int r)
{
if (l == r)
{
segtree[x] = vec[l];
return;
}
int mid = (l + r) / 2;
build(2 * x + 1, l, mid);
build(2 * x + 2, mid + 1, r);
recalculate(x);
}
void build()
{
build(0, 0, size - 1);
}
void set(int id, T val)
{
vec[id] = val;
}
void update(int x, int l, int r, int id, T val)
{
if (l == r)
{
segtree[x] = val;
return;
}
int mid = (l + r) / 2;
if (id <= mid)
{
update(2 * x + 1, l, mid, id, val);
}
else
{
update(2 * x + 2, mid + 1, r, id, val);
}
recalculate(x);
}
void update(int id, T val)
{
update(0, 0, size - 1, id, val);
}
int ans;
void query(int x, int l, int r, int lx, int rx, int v)
{
if (lx > r || rx < l || ans!=-1 || segtree[x] > v)
{
return;
}
if (l == r)
{
ans = l;
}
int mid = (l + r) / 2;
query(2 * x + 1, l, mid, lx, rx, v);
query(2 * x + 2, mid + 1, r, lx, rx, v);
}
int query(int lx, int rx, int v)
{
ans = -1;
query(0, 0, size - 1, lx, rx, v);
return ans;
}
};
int main() {
// usaco();
fastio();
int n, q;
cin >> n >> q;
SegTree<int> segtree;
segtree.init(n+1, 2e9);
segtree.build();
frange(_, q) {
char c;
int x, a;
cin >> c >> x >> a;
// cout << x << " ";
if(c == 'M') {
segtree.update(a, x);
}
else {
cout << segtree.query(a, n, x) << "\n";
}
}
}
Compilation message
deda.cpp: In function 'void usaco()':
deda.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
65 ms |
8016 KB |
Output is correct |
5 |
Correct |
75 ms |
5896 KB |
Output is correct |
6 |
Correct |
80 ms |
7700 KB |
Output is correct |
7 |
Correct |
77 ms |
7776 KB |
Output is correct |