답안 #211406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211406 2020-03-20T09:51:43 Z ahzong Deda (COCI17_deda) C++17
20 / 140
465 ms 8252 KB
/*input
3 4
M 10 3
M 5 1
D 20 2
D 5 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

vector<int> t;

int query(int v, int tl, int tr, int l, int r, int x)
{
	if(tl > r || tr < l) return -2;
	if(l <= tl && tr <= r)
	{
		if(t[v] > x) return -2;
		while(tl != tr)
		{
			int tm = (tl + tr)/2;
			if(t[2 * v] <= x)
			{
				v = 2 * v;
				tr = tm;
			}
			else
			{
				v = 2 * v + 1;
				tl = tm + 1;
			}
		}
		return tl;
	}
	int tm = (tl + tr)/2;
	int res = query(2 * v, tl, tm, l, r, x);
	if(res != -2) return res;
	return query(2 * v + 1, tm + 1, tr, l, r, x);
}

void update(int v, int tl, int tr, int pos, int x)
{
	if(tl == tr) t[v] = x;
	else
	{
		int tm = (tl + tr)/2;
		if(pos <= tm) update(2 * v, tl, tm, pos, x);
		else update(2 * v + 1, tm + 1, tr, pos, x);
		t[v] = min(t[2 * v], t[2 * v + 1]);
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q; cin >> n >> q;
    t.resize(4 * n);
    for(int i = 0; i < 4 * n; i++) t[i] = 100;
    while(q--)
    {
    	char c; cin >> c;
    	if(c == 'D') //query
    	{
    		int y, b; cin >> y >> b;
    		b--;
    		int res = query(1, 0, n - 1, b, n - 1, y);
    		cout << query(1, 0, n - 1, b, n - 1, y) + 1 << endl;
    	}
    	else //update
    	{
    		int x, a; cin >> x >> a;
    		a--;
    		update(1, 0, n - 1, a, x);
    	}
    }

    return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:79:11: warning: unused variable 'res' [-Wunused-variable]
       int res = query(1, 0, n - 1, b, n - 1, y);
           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Incorrect 14 ms 384 KB Output isn't correct
4 Incorrect 465 ms 8252 KB Output isn't correct
5 Incorrect 361 ms 6008 KB Output isn't correct
6 Incorrect 389 ms 7076 KB Output isn't correct
7 Incorrect 402 ms 8032 KB Output isn't correct