답안 #523454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523454 2022-02-07T16:37:53 Z tmn2005 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
378 ms 262148 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define fr first
#define sc second

#define vec vector
#define ret return

#define ins insert
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()

const int N = 1e7+12, INF = 1e9, mod = 1e9+7;
int lz[N*4], sum[N*4];

void push(int p, int len) {
    if (lz[p] != -1) {
        sum[p] = len * lz[p];
        if (len > 1) {
            lz[2 * p] = lz[2 * p + 1] = lz[p];
        }
        lz[p] = -1;
    }
}
void update(int p, int l, int r, int x, int y) {
    push(p, r - l + 1);
    if (l > y || r < x) return;
    if (l >= x && r <= y) {
        lz[p] = 1;
        push(p, r - l + 1);
        return;
    }
    int m = (l + r) / 2;
    update(2 * p, l, m, x, y);
    update(2 * p + 1, m + 1, r, x, y);
    sum[p] = sum[2 * p] + sum[2 * p + 1];
}
int get(int p, int l, int r, int x, int y) {
    push(p, r - l + 1);
    if (l > y || r < x) return 0;
    if (l >= x && r <= y) {
        return sum[p];
    }
    int m = (l + r) / 2;
    return get(2 * p, l, m, x, y) + get(2 * p + 1, m + 1, r, x, y);
}

main(){
	int n;
	cin>>n;
	memset(lz, -1, sizeof lz);
	int c = 0;
	for(int i=1; i<=n; i++){
		int z, x, y;
		cin>>z>>x>>y;
		if(z == 2){
			update(1, 1, 10000000, x + c, y + c);
		}
		else{
			int ans = get(1, 1, 10000000, x + c, y + c);
			cout<<ans<<"\n";
			c = ans;
		}
	}
	
	
	
	return 0;
}



Compilation message

apple.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 156868 KB Output is correct
2 Correct 62 ms 156920 KB Output is correct
3 Correct 62 ms 156868 KB Output is correct
4 Correct 81 ms 166320 KB Output is correct
5 Correct 88 ms 167800 KB Output is correct
6 Correct 83 ms 166816 KB Output is correct
7 Correct 83 ms 167720 KB Output is correct
8 Correct 207 ms 208196 KB Output is correct
9 Correct 347 ms 223976 KB Output is correct
10 Correct 378 ms 247924 KB Output is correct
11 Runtime error 293 ms 262148 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -