제출 #764068

#제출 시각아이디문제언어결과실행 시간메모리
764068vjudge1Fountain (eJOI20_fountain)C++14
100 / 100
259 ms27648 KiB
//srand(time(0)) - always changing
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fopen(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
#define all(x) (x).begin(), (x).end()
#define len(x) (int)x.size()
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define elif else if
#define F first
#define S second
#define int long long

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
using namespace __gnu_pbds;

const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const int P = 911;
const ll INF = 1e18;

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap (a, b);
	}
	return a;
}

ll __sqrt(ll x) {
	ll result = 0;
	for (ll k = 1ll << 30; k != 0; k >>= 1) {
		if ((result + k) * (result + k) <= x) {
			result += k;
		}
	}
	return result;
}

int d[N], c[N], r[N], v[N], ps[N];
vector <int> qu[N];
map <pair <int, int>, int> ans;

void solve() {
	int n, q;
	vector <int> st;
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> d[i] >> c[i];
	}
	for (int i = 1; i <= q; i++) {
		cin >> r[i] >> v[i];
		qu[r[i]].pb(v[i]);
	}
	for (int i = n; i > 0; i--) {
		while (!st.empty()) {
			if (d[i] < d[st.back()]) break;
			else st.popb();
		}
		ps[i] = c[i];
		if (!st.empty()) {
			ps[i] += ps[st.back()];
		}
		st.pb(i);
		for (int it: qu[i]) {
//			cout << "DBG";
			int l = 0, r = len(st) - 1;
			while (l <= r) {
				int m = l + r >> 1;
//				cout << l << ' ' << r << '\n';
				int act = st[m];
				if (it - (ps[i] - ps[act]) > 0) r = m - 1;
				else l = m + 1;
			}
			if (it - ps[i] > 0) ans[{i, it}] = 0; 
			else ans[{i, it}] = st[r + 1];
		}
	}
	for (int i = 1; i <= q; i++) {
		cout << ans[{r[i], v[i]}] << '\n';
	}
}

const bool Cases = 0;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int TT = 1;
	if (Cases) cin >> TT;
	while (TT--) {
		solve();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

fountain.cpp: In function 'void solve()':
fountain.cpp:80:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |     int m = l + r >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...