답안 #987124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987124 2024-05-22T03:19:05 Z Sunbae 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
427 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
struct Vertex{
	Vertex *l = nullptr, *r = nullptr;
	int low, high, sum = 0; bool op = false;
	Vertex(int L, int R){low = L; high = R;}
	~Vertex(){if(l) delete l; if(r) delete r;}
	void propagate(){
		if(low != high){
			int mid = low + ((high-low)>>1);
			if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
			l->op = r->op = true;
		}
		op = false;
	}
	void upd(int L, int R){
		if(op){sum = (high-low+1); propagate();}
		if(low > R || high < L) return;
		if(L <= low && high <= R){
			sum = high-low+1; op = true; propagate(); return;
		}
		int mid = low + ((high-low)>>1);
		if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
		l->upd(L, R); r->upd(L, R);
		sum = ((l)? l->sum : 0) + ((r)? r->sum :  0);
	}
	int qry(int L, int R){
		if(op){sum = (high-low+1); propagate();}
		if(low > R || high < L) return 0;
		if(L <= low && high <= R) return sum;
		int mid = low + ((high-low)>>1);
		if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
		return ((l)? l->qry(L, R) : 0) + ((r)? r->qry(L, R) : 0);
	}
};	
signed main(){
	int q, c = 0; scanf("%d", &q);
	Vertex* seg = new Vertex(0, 1e9+1);
	while(q--){
		int t, x, y; scanf("%d %d %d", &t, &x, &y);
		if(t == 1){
			printf("%d\n", c = seg->qry(x+c, y+c));
		}else{
			seg->upd(x+c, y+c);
		}
	}
}

Compilation message

apple.cpp: In member function 'void Vertex::propagate()':
apple.cpp:11:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   11 |    if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |    ^~
apple.cpp:11:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   11 |    if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |                                     ^~
apple.cpp: In member function 'void Vertex::upd(int, int)':
apple.cpp:23:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   23 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |   ^~
apple.cpp:23:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   23 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |                                    ^~
apple.cpp: In member function 'int Vertex::qry(int, int)':
apple.cpp:32:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   32 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |   ^~
apple.cpp:32:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   32 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |                                    ^~
apple.cpp: In function 'int main()':
apple.cpp:37:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  int q, c = 0; scanf("%d", &q);
      |                ~~~~~^~~~~~~~~~
apple.cpp:40:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   int t, x, y; scanf("%d %d %d", &t, &x, &y);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 15 ms 8796 KB Output is correct
5 Correct 17 ms 10428 KB Output is correct
6 Correct 18 ms 10072 KB Output is correct
7 Correct 19 ms 10588 KB Output is correct
8 Correct 169 ms 77788 KB Output is correct
9 Correct 344 ms 132688 KB Output is correct
10 Correct 393 ms 148532 KB Output is correct
11 Correct 386 ms 161104 KB Output is correct
12 Correct 427 ms 166592 KB Output is correct
13 Correct 348 ms 207192 KB Output is correct
14 Correct 376 ms 209116 KB Output is correct
15 Runtime error 364 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -