답안 #918694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918694 2024-01-30T09:20:05 Z AndrijaM 원숭이와 사과 나무 (IZhO12_apple) C++17
100 / 100
268 ms 126548 KB
#include <bits/stdc++.h>
using namespace std;
const int mxN = (int)3e5+10;
int mx=(int)1e9, segTree[mxN*40], lazy[mxN*40];
int L[mxN*40], R[mxN*40], IND = 1, q,c;

void prop(int p, int l, int r){
	if(!p or l==r or lazy[p]==-1) return;
	int mid = (l+r)/2;
	if(!L[p]) L[p]=++IND;
	if(!R[p]) R[p]=++IND;
	lazy[L[p]]=lazy[R[p]]=lazy[p]; lazy[p]=-1;
	segTree[L[p]] = (mid-l+1)*lazy[L[p]];
	segTree[R[p]] = (r-mid)*lazy[R[p]];
}

void upd(int i, int j, int v, int p=1, int l=1, int r=mx){
	if(i>r or j<l or i>j or !p) return; prop(p,l,r);
	if(i<=l and r<=j){ segTree[p] = v*(r-l+1); lazy[p] = v; return; }
	int mid = (l+r)/2;
	if(i<=mid){
		if(!L[p]) L[p]=++IND;
		upd(i,j,v,L[p],l,mid);
	}
	if(j>mid){
		if(!R[p]) R[p]=++IND;
		upd(i,j,v,R[p],mid+1,r);
	}
	segTree[p]=segTree[L[p]]+segTree[R[p]];
}

int query(int i, int j, int p=1, int l=1, int r=mx){
	if(i>r or j<l or i>j or !p) return 0; prop(p,l,r);
	if(i<=l and r<=j) return segTree[p];
	int mid = (l+r)/2;
	return query(i,j,L[p],l,mid)+query(i,j,R[p],mid+1,r);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> q; memset(lazy,-1,sizeof(lazy));
    while(q--){
        int t, x, y; cin >> t >> x >> y; x+=c, y+=c;
        if(t==1) c = query(x,y), cout << c << "\n";
        else upd(x,y,1);
    }
}

Compilation message

apple.cpp: In function 'void upd(int, int, int, int, int, int)':
apple.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   18 |  if(i>r or j<l or i>j or !p) return; prop(p,l,r);
      |  ^~
apple.cpp:18:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   18 |  if(i>r or j<l or i>j or !p) return; prop(p,l,r);
      |                                      ^~~~
apple.cpp: In function 'int query(int, int, int, int, int)':
apple.cpp:33:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   33 |  if(i>r or j<l or i>j or !p) return 0; prop(p,l,r);
      |  ^~
apple.cpp:33:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   33 |  if(i>r or j<l or i>j or !p) return 0; prop(p,l,r);
      |                                        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 49496 KB Output is correct
2 Correct 8 ms 49496 KB Output is correct
3 Correct 11 ms 49624 KB Output is correct
4 Correct 16 ms 50812 KB Output is correct
5 Correct 18 ms 51036 KB Output is correct
6 Correct 18 ms 51108 KB Output is correct
7 Correct 18 ms 51036 KB Output is correct
8 Correct 79 ms 66900 KB Output is correct
9 Correct 174 ms 75604 KB Output is correct
10 Correct 184 ms 81232 KB Output is correct
11 Correct 190 ms 83028 KB Output is correct
12 Correct 198 ms 83540 KB Output is correct
13 Correct 186 ms 90448 KB Output is correct
14 Correct 162 ms 90708 KB Output is correct
15 Correct 268 ms 125408 KB Output is correct
16 Correct 257 ms 125424 KB Output is correct
17 Correct 167 ms 93776 KB Output is correct
18 Correct 175 ms 94032 KB Output is correct
19 Correct 257 ms 126548 KB Output is correct
20 Correct 262 ms 126548 KB Output is correct