답안 #652745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
652745 2022-10-24T06:29:16 Z dilaylay_dilaylaylay 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
42 ms 34088 KB
#include <iostream>
#include <bits/stdc++.h>    
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;

#define int long long
#define ll long long
#define vi vector<long long>
#define pb push_back
#define sz(s) (int)s.size()
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define pp pair<int,int>
#define FF first
#define SS second
#define endl "\n"

const int N = 1e6 + 2, N3 = 1e3 + 6, inf = 1e9 + 7, LOG = 20;
map<char, int> md{{'N', 0}, {'E', 1}, {'S', 2}, {'W', 3}};
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
string stepDir = "RDLU";

int m, t[N * 4], add[N * 4];

void push(int v, int tl, int tr){
	if (add[v] == 0) return;
    t[v] = add[v] * (tr - tl + 1); 
	if (tl < tr) {
		add[v + v] = add[v];
		add[v + v + 1] = add[v];
	}
	add[v] = 0;
}
 
int get_sum(int l, int r, int v = 1, int tl = 1, int tr = 1e6) {
	push(v, tl, tr);
    if (l <= tl && tr <= r) {
        return t[v];
    }
	
	if (tr < l || r < tl) {
        return 0;
    }
    int tm = (tl + tr) / 2;
    return get_sum(l, r, v * 2, tl, tm) + get_sum(l, r, v * 2 + 1, tm + 1, tr);
}
 
void upd(int l, int r, int val, int v = 1, int tl = 1, int tr = 1e6) {
	push(v, tl, tr);
	if (tr < l || r < tl) return;

	if (l <= tl && tr <= r) {
		add[v] = val;
		push(v, tl, tr);
		return;
	}	
	
	int tm = (tl + tr) / 2;
	upd (l, r, val, v * 2, tl, tm);
	upd(l, r, val, v * 2 + 1, tm + 1, tr);
	t[v] = t[v * 2 + 1] + t[v * 2];
}

main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	
//	freopen("triangles.in", "r", stdin);
//	freopen("triangles.out", "w", stdout);
	
	ll last = 0;
	cin >> m;
	while (m--) {
		int d, x, y;
		cin >> d >> x >> y;
		if (d == 2) {
			upd(x + last, y + last, 1);
		}
		else {
			last = get_sum(x + last, y + last);
			cout << last << "\n";
		}
	}
		
	return 0;
}

Compilation message

apple.cpp:13: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   13 | #pragma comment(linker, "/stack:200000000")
      | 
apple.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 21 ms 28928 KB Output is correct
5 Correct 25 ms 32196 KB Output is correct
6 Correct 24 ms 29384 KB Output is correct
7 Correct 24 ms 32340 KB Output is correct
8 Incorrect 42 ms 34088 KB Output isn't correct
9 Halted 0 ms 0 KB -