답안 #84021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84021 2018-11-12T12:02:25 Z sams Deda (COCI17_deda) C++14
140 / 140
388 ms 4672 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN=2e5+10, INF=0x3f3f3f3f;

int n, q, seg[4*MAXN];

void upd(int i, int x, int u=1, int l=1, int r=n){

	if(l==r){
		seg[u]=x;
		return;
	}

	int mid=(l+r)/2;

	if(i<=mid) upd(i, x, 2*u, l, mid);
	else upd(i, x, 2*u+1, mid+1, r);
	seg[u]=min(seg[2*u], seg[2*u+1]);
}

int search_seg(int b, int x, int u=1, int l=1, int r=n){
	
	if(seg[u]>x) return INF;

	if(b>r) return INF;

	if(l==r) return l;

	int mid=(l+r)/2;

	if(l<b) return min(search_seg(b, x, 2*u, l, mid), search_seg(b, x, 2*u+1, mid+1, r));

	if(seg[2*u]<=x) return search_seg(b, x, 2*u, l, mid);

	return search_seg(b, x, 2*u+1, mid+1, r);
}

int main(){
	
	scanf("%d%d", &n, &q);
	memset(seg, INF, sizeof seg);
	for(int i=0;i<q;++i){

		char c;
		int x, a;

		scanf(" %c %d %d", &c, &x, &a);

		if(c=='M'){
			upd(a, x);
		}else{
			int k=search_seg(a, x);
			if(k>=INF) printf("-1\n");
			else printf("%d\n", k);
		}
	}

	return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:42: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:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c %d %d", &c, &x, &a);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 7 ms 3652 KB Output is correct
4 Correct 148 ms 4604 KB Output is correct
5 Correct 185 ms 4604 KB Output is correct
6 Correct 195 ms 4604 KB Output is correct
7 Correct 388 ms 4672 KB Output is correct