답안 #884635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884635 2023-12-07T19:32:43 Z OAleksa 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
143 ms 132160 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
//#define int long long
const int N = 1e7 + 69;
int st[4 * N], q, c;
void push(int v, int tl, int tr) {
	int mid = (tl + tr) / 2;
	int s = tr - tl + 1;
	if (st[v] == s) {
		st[v * 2] = mid - tl + 1;
		st[v * 2 + 1] = tr - mid;
	}
}
void upd(int v, int tl, int tr, int l, int r) {
	if (tl > r || tr < l)
		return;
	else if (tl >= l && tr <= r) 
		st[v] = (tr - tl + 1);
	else {
		int mid = (tl + tr) / 2;
		push(v, tl, tr);
		upd(v * 2, tl, mid, l, r);
		upd(v * 2 + 1, mid + 1, tr, l, r);
		st[v] = st[v * 2] + st[v * 2 + 1];
	}
}
int get(int v, int tl, int tr, int l, int r) {
	if (tl > r || tr < l)
		return 0;
	else if (tl >= l && tr <= r)
		return st[v];
	else {
		int mid = (tl + tr) / 2;
		push(v, tl, tr);
		return get(v * 2, tl, mid, l, r) + get(v * 2 + 1, mid + 1, tr, l, r);
	}
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  int tt = 1;
	//cin >> tt;
  while (tt--) {
   	cin >> q;
   	while (q--) {
   		int t, l, r;
   		cin >> t >> l >> r;
   		l += c, r += c;
   		if (t == 2) 
   			upd(1, 1, N - 1, l, r);
   		else {
				c = get(1, 1, N - 1, l, r);
				cout << c << '\n';
   		}
   	}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 11612 KB Output is correct
5 Correct 9 ms 16220 KB Output is correct
6 Correct 9 ms 16888 KB Output is correct
7 Correct 9 ms 16732 KB Output is correct
8 Correct 66 ms 58132 KB Output is correct
9 Correct 143 ms 70516 KB Output is correct
10 Correct 111 ms 98612 KB Output is correct
11 Correct 123 ms 122332 KB Output is correct
12 Correct 140 ms 132160 KB Output is correct
13 Incorrect 41 ms 123432 KB Output isn't correct
14 Halted 0 ms 0 KB -