답안 #84018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84018 2018-11-12T11:53:55 Z sams Deda (COCI17_deda) C++14
140 / 140
214 ms 18372 KB
#include <bits/stdc++.h>

using namespace std;

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

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

// Segment Tree 

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);
			/*cout << i << "\n";
			for(int j=1;j<=10;++j){
				cout << " i: " << j << " " << seg[j] << "\n";
			}
			*/
		}else{
			//cout << i << "\n";
			int k=search_seg(a, x);
			//cout << " aaaa " << seg[1] << " essa porra ta errada\n" <<"\n";
			if(k>=INF) printf("-1\n");
			else printf("%d\n", k);
		}
	}

	return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:46: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:53: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 6 ms 3448 KB Output is correct
2 Correct 5 ms 3652 KB Output is correct
3 Correct 7 ms 3816 KB Output is correct
4 Correct 149 ms 8176 KB Output is correct
5 Correct 172 ms 11092 KB Output is correct
6 Correct 214 ms 14952 KB Output is correct
7 Correct 200 ms 18372 KB Output is correct