Submission #853218

# Submission time Handle Problem Language Result Execution time Memory
853218 2023-09-23T16:26:46 Z serifefedartar Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
328 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 2e5 + 5;

struct Node {
	int l, r, sum, lazy;
	Node *ptrL, *ptrR;

	Node(int a, int b) : l(a), r(b), ptrL(NULL), ptrR(NULL), sum(0), lazy(0) { };
	void add() {
		if (ptrL == NULL && l != r) {
			int mid = (l + r) / 2;
			ptrL = new Node(l, mid);
			ptrR = new Node(mid+1, r);
		}
	}

	void push() {
		if (lazy) {
			sum = r - l + 1;
			if (l != r) {
				add();
				ptrL->lazy = 1;
				ptrR->lazy = 1;
			}
			lazy = 0;
		}
	}

	void update(int a, int b) {
		push();
		if (l > b || a > r)
			return ;
		if (a <= l && r <= b) {
			lazy = 1;
			push();
			return ;
		}
		add();
		ptrL->update(a, b);
		ptrR->update(a, b);
		sum = ptrL->sum + ptrR->sum; 
	}

	int query(int a, int b) {
		push();
		if (l > b || a > r)
			return 0;
		if (a <= l && r <= b)
			return sum;
		add();
		return ptrL->query(a, b) + ptrR->query(a, b);
	}
};

int main() {
	fast
	int M;
	cin >> M;

	Node *root = new Node(1, 1e12);
	int C = 0;
	while (M--) {
		int D, X, Y;
		cin >> D >> X >> Y;
		X += C;
		Y += C;
		if (D == 1) {
			C = root->query(X, Y);
			cout << C << "\n";
		} else {
			root->update(X, Y);
		}
	}
}

Compilation message

apple.cpp: In constructor 'Node::Node(int, int)':
apple.cpp:14:15: warning: 'Node::ptrR' will be initialized after [-Wreorder]
   14 |  Node *ptrL, *ptrR;
      |               ^~~~
apple.cpp:13:12: warning:   'int Node::sum' [-Wreorder]
   13 |  int l, r, sum, lazy;
      |            ^~~
apple.cpp:16:2: warning:   when initialized here [-Wreorder]
   16 |  Node(int a, int b) : l(a), r(b), ptrL(NULL), ptrR(NULL), sum(0), lazy(0) { };
      |  ^~~~
apple.cpp: In function 'int main()':
apple.cpp:68:27: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+12' to '2147483647' [-Woverflow]
   68 |  Node *root = new Node(1, 1e12);
      |                           ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 12 ms 8280 KB Output is correct
5 Correct 16 ms 10072 KB Output is correct
6 Correct 19 ms 9564 KB Output is correct
7 Correct 19 ms 10072 KB Output is correct
8 Correct 150 ms 76368 KB Output is correct
9 Correct 292 ms 128984 KB Output is correct
10 Correct 321 ms 145136 KB Output is correct
11 Correct 319 ms 155436 KB Output is correct
12 Correct 328 ms 161928 KB Output is correct
13 Runtime error 212 ms 262144 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -