답안 #987125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987125 2024-05-22T03:21:41 Z Sunbae 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
396 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(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: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 20 ms 8508 KB Output is correct
5 Correct 18 ms 10328 KB Output is correct
6 Correct 17 ms 10076 KB Output is correct
7 Correct 18 ms 10320 KB Output is correct
8 Correct 167 ms 77088 KB Output is correct
9 Correct 341 ms 130852 KB Output is correct
10 Correct 352 ms 146768 KB Output is correct
11 Correct 385 ms 159416 KB Output is correct
12 Correct 330 ms 164948 KB Output is correct
13 Correct 342 ms 204948 KB Output is correct
14 Correct 343 ms 207004 KB Output is correct
15 Runtime error 396 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -