답안 #93458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93458 2019-01-08T13:57:10 Z Aydarov03 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
802 ms 263168 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
vector <int> ans;

struct st
{
		int l , r , val;
		bool add;
		st()
		{
			l = r = val = add = 0;
		}
}tree[N * 150];

int cnt = 1;

void push( int v , int tl , int tr )
{
		if(tl != tr)
		{			
			if( !tree[v].l )tree[v].l = ++cnt;
			if( !tree[v].r )tree[v].r = ++cnt;
		}
		if( !tree[v].add || tree[v].val )return;
		
		tree[v].val = tr - tl + 1;
		tree[v].add = 0;
		
		if( tl != tr )
		tree[ tree[v].l ].add = tree[ tree[v].r ].add = 1;
}

void upd( int l , int r , int v = 1 , int tl = 1 , int tr = 1e9 )
{
		push( v , tl , tr );
		if( tl > r || l > tr )return;
		
		if(l <= tl && tr <= r)
		{
				tree[v].add = 1;
				push( v , tl , tr );
				return;
		}
		
		int tm = (tl + tr) >> 1;
		
		upd( l , r , tree[v].l , tl , tm );
		upd( l , r , tree[v].r , tm+1 , tr );
}


int get( int l , int r , int v = 1 , int tl = 1 , int tr = 1e9)
{
	push( v , tl , tr );
	
	if( tl > r || tr < l )
		return 0;
	if( l <= tl && tr <= r )
	{
		if( tree[v].val )
		return tree[v].val;
	}
	
	if(tl == tr && !tree[v].val )return 0;
	
	int tm = (tl + tr) >> 1;
	
	return get( l , r , tree[v].l , tl , tm ) + get( l , r , tree[v].r , tm+1 , tr );
}



main()
{
	int t , c = 0;
	cin >> t;
	
	while( t-- )
	{
		int tp , l , r;		
		scanf("%d%d%d" , &tp , &l , &r );
		
		l += c , r += c;
		
		if( tp == 1 )
		{
			ans.push_back( c = get( l , r ) );
		}
		
		if( tp == 2 )
			upd(l , r);
	}
	
	for(auto c : ans)cout << c << endl;
	
}

Compilation message

apple.cpp:74:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
apple.cpp: In function 'int main()':
apple.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d" , &tp , &l , &r );
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 235128 KB Output is correct
2 Correct 190 ms 235084 KB Output is correct
3 Correct 187 ms 235128 KB Output is correct
4 Correct 257 ms 235228 KB Output is correct
5 Correct 216 ms 235256 KB Output is correct
6 Correct 214 ms 235368 KB Output is correct
7 Correct 223 ms 235272 KB Output is correct
8 Correct 467 ms 235768 KB Output is correct
9 Correct 617 ms 235892 KB Output is correct
10 Correct 601 ms 235892 KB Output is correct
11 Correct 802 ms 235908 KB Output is correct
12 Correct 595 ms 236036 KB Output is correct
13 Runtime error 681 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -