#include<bits/stdc++.h>
#pragma optimize ("g",on)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define nl '\n'
#define popb pop_back()
#define sz size()
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define fix fixed << setprecision
#define pii pair<int, int>
#define E exit (0)
#define int long long
const int inf = (1ll << 62ll), N = 1e6 + 2, mod = 1e9 + 7;
vector<pii> dd = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
signed main() {
//freopen("invtrans.in", "r", stdin);
//freopen("invtrans.out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int n, q;
cin >> n >> q;
int d[n + 1], c[n + 1];
bool ok = 1;
for (int i = 1; i <= n; i++) {
cin >> d[i] >> c[i];
if (i > 1 && d[i] <= d[i - 1]) ok = 0;
}
if (ok) {
int pref[n + 1];
pref[0] = 0;
for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + c[i];
while (q--) {
int r, v;
cin >> r >> v;
int tl = r, tr = n, ans =0;
while (tl <= tr) {
int mid = (tl + tr) / 2;
if (pref[mid] - pref[r - 1] >= v) {
ans = mid;
tr = mid - 1;
}else tl = mid + 1;
}
cout << ans << nl;
}
return 0;
}
while (q--) {
int r, v;
cin >> r >> v;
int last = 0, ans = 0;
for (int i = r; i <= n; i++) {
if (d[i] > last) {
last = d[i];
v -= c[i];
if (v <= 0) {
ans = i;
break;
}
}
}
cout << ans << nl;
}
}
Compilation message
fountain.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize ("g",on)
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
3196 KB |
Output is correct |
2 |
Correct |
90 ms |
3124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
104 ms |
3196 KB |
Output is correct |
9 |
Correct |
90 ms |
3124 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Execution timed out |
1578 ms |
1512 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |