답안 #52528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52528 2018-06-26T06:41:08 Z hamzqq9 Deda (COCI17_deda) C++14
140 / 140
211 ms 3712 KB
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 1050000001
#define N 200005
#define LOG 19
#define magic 100
#define KOK 350
#define EPS 0.000000000001
#define pw(x) 1ll*((1ll)<<(x))
#define PI 3.1415926535
using namespace std;

int n,q,x,y,S[N*4];

int get(int node,int bas,int son,int x,int y,int val) {

	if(bas>y || son<x) return inf;

	if(bas>=x && son<=y) {

		if(S[node]>val) return inf;

		if(bas==son) return bas;

		if(S[node*2]<=val) return get(node*2,bas,orta,x,y,val);

		if(S[node*2+1]<=val) return get(node*2+1,orta+1,son,x,y,val);

	}

	int res=get(node*2,bas,orta,x,y,val);

	if(res!=inf) return res;

	return get(node*2+1,orta+1,son,x,y,val);

}

void up(int node,int bas,int son,int x,int val) {

	if(bas>x || son<x) return ;

	if(bas==x && son==x) {

		S[node]=val;

		return ;

	}

	up(node*2,bas,orta,x,val);
	up(node*2+1,orta+1,son,x,val);

	umin(S[node],min(S[node*2],S[node*2+1]));

}

void build(int node,int bas,int son) {

	S[node]=inf;

	if(bas==son) return ;

	build(node*2,bas,orta);
	build(node*2+1,orta+1,son);

}

int main() {

	#if 0
	freopen("input.txt","r",stdin);
 	#endif

	scanf("%d %d",&n,&q);

	build(1,1,n);

	while(q--) {

		char type;

		scanf(" %c %d %d",&type,&x,&y);

		if(type=='M') {

			up(1,1,n,y,x);

		}
		else {

			int res=get(1,1,n,y,n,x);

			if(res==inf) res=-1;

			printf("%d\n",res);

		}

	}

}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:103:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
deda.cpp:111:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c %d %d",&type,&x,&y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 5 ms 516 KB Output is correct
4 Correct 194 ms 3712 KB Output is correct
5 Correct 201 ms 3712 KB Output is correct
6 Correct 171 ms 3712 KB Output is correct
7 Correct 211 ms 3712 KB Output is correct