답안 #987127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987127 2024-05-22T03:23:59 Z Sunbae 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
418 ms 262144 KB
#include <stdio.h>
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(1, 1e9);
	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:10:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   10 |    if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |    ^~
apple.cpp:10:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   10 |    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:22:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   22 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |   ^~
apple.cpp:22:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   22 |   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:31:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   31 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |   ^~
apple.cpp:31:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   31 |   if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
      |                                    ^~
apple.cpp: In function 'int main()':
apple.cpp:36:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  int q, c = 0; scanf("%d", &q);
      |                ~~~~~^~~~~~~~~~
apple.cpp:39:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   int t, x, y; scanf("%d %d %d", &t, &x, &y);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 14 ms 8540 KB Output is correct
5 Correct 18 ms 10332 KB Output is correct
6 Correct 18 ms 10072 KB Output is correct
7 Correct 19 ms 10332 KB Output is correct
8 Correct 174 ms 76944 KB Output is correct
9 Correct 323 ms 130968 KB Output is correct
10 Correct 353 ms 146740 KB Output is correct
11 Correct 398 ms 159572 KB Output is correct
12 Correct 370 ms 165080 KB Output is correct
13 Correct 312 ms 205144 KB Output is correct
14 Correct 371 ms 207056 KB Output is correct
15 Runtime error 418 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -