#include "weirdtree.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int maxn = 1e6 + 200, maxm = 1e4 + 200, inf = 1e9;
int n;
ll t[maxn * 4];
pair<ll, ll> tmx[maxn * 4];
void upd(int pos, ll val, int v = 1, int tl = 1, int tr = n){
if (tl == tr){
t[v] += val;
tmx[v].s = tl;
tmx[v].f += val;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm){
upd(pos, val, v + v, tl, tm);
}
else{
upd(pos, val, v + v + 1, tm + 1, tr);
}
t[v] = t[v + v] + t[v + v + 1];
if (tmx[v + v].f == tmx[v + v + 1].f){
tmx[v].f = tmx[v + v].f, tmx[v].s = min(tmx[v + v].s, tmx[v + v + 1].s);
}
else{
tmx[v] = max(tmx[v + v], tmx[v + v + 1]);
}
}
ll get(int l, int r, int v = 1, int tl = 1, int tr = n){
if (l <= tl && tr <= r){
return t[v];
}
if (l > tr || r < tl)
return 0;
int tm = (tl + tr) / 2;
return get(l, r, v + v, tl, tm) + get(l, r, v + v + 1, tm + 1, tr);
}
pair<ll, ll> getmx(int l, int r, int v = 1, int tl = 1, int tr = n){
if (l <= tl && tr <= r){
return tmx[v];
}
if (l > tr || r < tl)
return mp(0, -inf);
int tm = (tl + tr) / 2;
pair<ll, ll> curl = getmx(l, r, v + v, tl, tm);
pair<ll, ll> curr = getmx(l, r, v + v + 1, tm + 1, tr);
if (curl.f == curr.f){
if (curl.s < curr.s)
return curl;
else
return curr;
}
else{
return max(curl, curr);
}
}
void initialise(int N, int Q, int h[]) {
// Your code here.
n = N;
for (int i = 1; i <= n; ++i){
upd(i, h[i]);
}
}
void cut(int l, int r, int k) {
if (k == 1){
pair<ll, ll> cur = getmx(l, r);
int pos = cur.s;
if (cur.f > 0){
upd(pos, -1);
}
}
}
void magic(int i, int x) {
// Your code here.
ll val = get(i, i);
ll z = x;
upd(i, z - val);
}
long long int inspect(int l, int r) {
// Your code here.
return get(l, r);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
51 ms |
7216 KB |
Output is correct |
4 |
Correct |
57 ms |
7332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
154 ms |
27668 KB |
Output is correct |
2 |
Correct |
156 ms |
27708 KB |
Output is correct |
3 |
Incorrect |
15 ms |
6868 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
51 ms |
7216 KB |
Output is correct |
4 |
Correct |
57 ms |
7332 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
51 ms |
7216 KB |
Output is correct |
4 |
Correct |
57 ms |
7332 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |