답안 #1030579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030579 2024-07-22T07:04:18 Z Gray 원숭이와 사과 나무 (IZhO12_apple) C++17
100 / 100
26 ms 3184 KB
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <ios>
#include <iostream>
#include <map>
#include <ratio>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long int
#define ld double
#define ln "\n"
#define ff first
#define ss second
using namespace std;
 
const ll inf=2e18;
 
void setio(string io=""){
	#ifndef LOCAL
	if (io.length()){
		freopen((io+".in").c_str(), "r", stdin);
		freopen((io+".out").c_str(), "w", stdout);
		return;
	}
	#endif
	ios_base::sync_with_stdio(0); cin.tie(nullptr);
}
 
struct Node{
	Node *left, *right;
	ll val, full;
	Node(){
		left=right=nullptr;
		val=full=0;
	}
	Node(ll _val, ll _full){
		left=right=nullptr;
		val=_val;
		full=_full;
	}
	void preprocess(ll tl, ll tr){
		ll tm = (tl+tr)/2;
		if (left and left->val!=(tm-tl+1)){
			left->val=(tm-tl+1);
		}

	}
	void update(ll tl, ll tr, ll l, ll r){
		if (full or l>r) return;
		else if (tl==l and tr==r){
			val=tr-tl+1;
			full=1;
		}else{
			ll tm = (tl+tr)/2;
			if (!left) left=new Node;
			left->update(tl, tm, l, min(r, tm));
			if (!right) right=new Node;
			right->update(tm+1, tr, max(tm+1, l), r);
			val=left->val+right->val;
		}
	}
	ll query(ll l, ll r, ll tl, ll tr){
		if (l>r) return 0;
		else if (l==tl and r==tr){
			return val;
		}else if (full) return r-l+1;
		else{
			ll tm = (tl+tr)/2;
			ll ans=0;
			// preprocess(tl, tr);
			if (left) ans+=left->query(l, min(r, tm), tl, tm);
			if (right) ans+=right->query(max(l, tm+1), r, tm+1, tr);
			return ans;
		}
	}
};
 
void solve(){
	Node tr;
	ll l=1, r=1e9;
	ll q; cin >> q;
	ll c=0;
	while (q--){
		ll t, x, y; cin >> t >> x >> y;
		if (t==1){
			c = tr.query(x+c, y+c, l, r);
			cout << c << ln;
		}else{
			tr.update(l, r, x+c, y+c);
		}
	}
}
 
int main(){
	setio();
	ll t=1;
	// cin >> t;
	while (t--) solve();
}

Compilation message

apple.cpp: In function 'void setio(std::string)':
apple.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen((io+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen((io+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 12 ms 1468 KB Output is correct
9 Correct 24 ms 2540 KB Output is correct
10 Correct 24 ms 2384 KB Output is correct
11 Correct 23 ms 2384 KB Output is correct
12 Correct 23 ms 2652 KB Output is correct
13 Correct 26 ms 2904 KB Output is correct
14 Correct 26 ms 3184 KB Output is correct
15 Correct 23 ms 2908 KB Output is correct
16 Correct 24 ms 3164 KB Output is correct
17 Correct 21 ms 3016 KB Output is correct
18 Correct 20 ms 2908 KB Output is correct
19 Correct 22 ms 3164 KB Output is correct
20 Correct 25 ms 3152 KB Output is correct