답안 #887299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887299 2023-12-14T08:45:56 Z alex_2008 원숭이와 사과 나무 (IZhO12_apple) C++14
100 / 100
345 ms 71764 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <bitset>
typedef long long ll;
using namespace std;
const int N = 1e7 + 10;
int sz = 1;
int lazy[N];
int sm[N];
int l[N];
int r[N];
void update(int v, int tl, int tr, int ql, int qr) {
	if (tl > qr || tr < ql) {
		return;
	}
	if (tl >= ql && tr <= qr) {
		sm[v] = (tr - tl + 1);
		lazy[v] = 1;
		return;
	}
	if (!l[v]) l[v] = ++sz;
	if (!r[v]) r[v] = ++sz;
	int tm = (tl + tr) / 2;
	if (lazy[v]) {
		lazy[l[v]] = 1;
		sm[l[v]] = (tm - tl + 1);
		lazy[r[v]] = 1;
		sm[r[v]] = (tr - tm);
		lazy[v] = 0;
	}
	update(l[v], tl, tm, ql, qr);
	update(r[v], tm + 1, tr, ql, qr);
	sm[v] = sm[l[v]] + sm[r[v]];
}
int sum(int v, int tl, int tr, int ql, int qr) {
	if (tr < ql || tl > qr) return 0;
	if (tl >= ql && tr <= qr) {
		return sm[v];
	}
	if (!l[v]) l[v] = ++sz;
	if (!r[v]) r[v] = ++sz;
	int tm = (tl + tr) / 2;
	if (lazy[v]) {
		lazy[l[v]] = 1;
		sm[l[v]] = (tm - tl + 1);
		lazy[r[v]] = 1;
		sm[r[v]] = (tr - tm);
		lazy[v] = 0;
	}
	return sum(l[v], tl, tm, ql, qr) + sum(r[v], tm + 1, tr, ql, qr);
}
int main() {
	int m, c = 0;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		int d, x, y;
		cin >> d >> x >> y;
		if (d == 2) {
			update(1, 1, 1e9, x + c, y + c);
		}
		else {
			c = sum(1, 1, 1e9, x + c, y + c);
			cout << c << "\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 15 ms 1888 KB Output is correct
5 Correct 18 ms 4184 KB Output is correct
6 Correct 17 ms 4176 KB Output is correct
7 Correct 20 ms 3836 KB Output is correct
8 Correct 99 ms 15444 KB Output is correct
9 Correct 219 ms 29608 KB Output is correct
10 Correct 230 ms 30880 KB Output is correct
11 Correct 229 ms 31568 KB Output is correct
12 Correct 261 ms 32240 KB Output is correct
13 Correct 238 ms 38716 KB Output is correct
14 Correct 233 ms 38996 KB Output is correct
15 Correct 289 ms 70408 KB Output is correct
16 Correct 292 ms 70772 KB Output is correct
17 Correct 239 ms 39596 KB Output is correct
18 Correct 225 ms 39704 KB Output is correct
19 Correct 345 ms 71504 KB Output is correct
20 Correct 285 ms 71764 KB Output is correct