# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
566371 | Aldas25 | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 335 ms | 173648 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
//#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 500100, MAXK = 20;
const ll INF = 1e18;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
typedef struct node * pt;
struct node {
ll le, ri;
ll sum;
ll lazy;
int leCh;
int riCh;
node () {}
node (ll _le, ll _ri) {
le = _le;
ri = _ri;
sum = 0;
lazy = 0;
leCh = 0;
riCh = 0;
}
void turn () {
lazy = 1;
sum = (ri) - (le) + 1;
}
};
node tree[100*100*1000];
int crId = 0;
int newNode (int le, int ri) {
++crId;
tree[crId] = node (le, ri);
return crId;
}
void nodeupd (int id) {
if (tree[id].le == tree[id].ri) return;
ll m = ((tree[id].le)+(tree[id].ri))/2;
if (!(tree[id].leCh)) tree[id].leCh = newNode (tree[id].le, m);
if (!(tree[id].riCh)) tree[id].riCh = newNode (m+1, tree[id].ri);
}
void shift (int cur) {
if ((tree[cur].lazy) == 0) return;
tree[cur].lazy = 0;
tree[tree[cur].leCh].turn();
tree[tree[cur].riCh].turn();
}
int root;
void upd (ll x, ll y, int cur = root) {
if (x > (tree[cur].ri) || (tree[cur].le) > y) return;
if (x <= (tree[cur].le) && (tree[cur].ri) <= y) {
tree[cur].turn();
return;
}
nodeupd(cur);
shift (cur);
upd (x, y, tree[cur].leCh);
upd (x, y, tree[cur].riCh);
tree[cur].sum = (tree[tree[cur].leCh].sum) + (tree[tree[cur].riCh].sum);
}
ll get (ll x, ll y, int cur = root) {
if (x > (tree[cur].ri) || (tree[cur].le) > y) return 0;
if (x <= (tree[cur].le) && (tree[cur].ri) <= y) return tree[cur].sum;
nodeupd(cur);
shift (cur);
return get(x, y, tree[cur].leCh) + get(x, y, tree[cur].riCh);
}
int main()
{
setIO();
root = newNode (0, 1e9+5);
int q; cin >> q;
ll c = 0;
while (q--) {
int d; ll x, y;
cin >> d >> x >> y;
x += c;
y += c;
// if (y > 1e6+1) exit(0);
if (d == 1) {
c = get(x,y);
cout << c << "\n";
} else upd(x,y);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |