# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
894602 |
2023-12-28T14:16:07 Z |
vjudge1 |
Index (COCI21_index) |
C++17 |
|
841 ms |
14628 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define russian setlocale(LC_ALL,"Russian_Russia.20866");
#define file freopen("condense2.in", "r", stdin), freopen("condense2.out", "w", stdout);
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pli pair<ll, int>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ins insert
#define mp make_pair
#define sz(x) x.size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mem(x) memset(x, 0, sizeof(x))
const ll N = 200010;
const ll M = 1e9 + 7;
const ll block = 316;
const ll mod = 1e9 + 7;
const ll P = 263;
const ld pi = acos(-1);
const ll inf = 9e18;
ll add(ll a, ll b) {
if(a + b < 0) return a + b + mod;
if(a + b >= mod) return a + b - mod;
return a + b;
}
ll sub(ll a, ll b) {
return (a - b + mod) % mod;
}
ll mul(ll a, ll b) {
return a * b % mod;
}
ll binpow(ll a, ll n) {
ll res = 1;
while(n) {
if(n & 1) res = mul(res, a);
a = mul(a, a);
n >>= 1;
}
return res;
}
ll inv(ll x) {
return binpow(x, mod - 2);
}
struct ask {
ll l, r, pos;
};
ask Q[N];
bool cmp(ask a, ask b) {
if(a.l / block == b.l / block) return (a.r < b.r);
return (a.l < b.l);
}
ll n, q;
ll p[N], t[N], ans[N];
void upd(ll k, ll x) {
for(ll i = k; i <= n; i += (i & (-i))) {
t[i] += x;
}
}
ll sum(ll k) {
ll res = 0LL;
for(ll i = k; i >= 1; i -= (i & (-i))) {
res += t[i];
}
return res;
}
ll cnt(ll l, ll r) {
return sum(r) - sum(l - 1);
}
void solve() {
cin >> n >> q;
ll mx = 0;
for(ll i = 1; i <= n; i++) {
cin >> p[i];
mx = max(mx, p[i]);
}
for(ll i = 1; i <= q; i++) {
cin >> Q[i].l >> Q[i].r;
Q[i].pos = i;
}
sort(Q + 1, Q + q + 1, cmp);
ll l = 1, r = 0;
for(ll i = 1; i <= q; i++) {
while(r < Q[i].r) r++, upd(p[r], 1);
while(l < Q[i].l) upd(p[l], -1), l++;
while(l > Q[i].l) l--, upd(p[l], 1);
while(r > Q[i].r) upd(p[r], -1), r--;
ll lo = 1, hi = n + 1;
while(hi > lo + 1) {
ll mid = (lo + hi) / 2;
if(cnt(mid, mx) >= mid) lo = mid;
else hi = mid;
}
ans[Q[i].pos] = lo;
}
for(ll i = 1; i <= q; i++) cout << ans[i] << '\n';
}
signed main() {
speed;
//file;
int test = 1;
//cin >> test;
while(test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6620 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6620 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6488 KB |
Output is correct |
11 |
Correct |
103 ms |
7672 KB |
Output is correct |
12 |
Correct |
103 ms |
7764 KB |
Output is correct |
13 |
Correct |
108 ms |
7836 KB |
Output is correct |
14 |
Correct |
97 ms |
7760 KB |
Output is correct |
15 |
Correct |
100 ms |
7768 KB |
Output is correct |
16 |
Correct |
101 ms |
7888 KB |
Output is correct |
17 |
Correct |
99 ms |
7840 KB |
Output is correct |
18 |
Correct |
103 ms |
7836 KB |
Output is correct |
19 |
Correct |
108 ms |
7836 KB |
Output is correct |
20 |
Correct |
99 ms |
7760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6620 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6488 KB |
Output is correct |
11 |
Correct |
103 ms |
7672 KB |
Output is correct |
12 |
Correct |
103 ms |
7764 KB |
Output is correct |
13 |
Correct |
108 ms |
7836 KB |
Output is correct |
14 |
Correct |
97 ms |
7760 KB |
Output is correct |
15 |
Correct |
100 ms |
7768 KB |
Output is correct |
16 |
Correct |
101 ms |
7888 KB |
Output is correct |
17 |
Correct |
99 ms |
7840 KB |
Output is correct |
18 |
Correct |
103 ms |
7836 KB |
Output is correct |
19 |
Correct |
108 ms |
7836 KB |
Output is correct |
20 |
Correct |
99 ms |
7760 KB |
Output is correct |
21 |
Correct |
737 ms |
14284 KB |
Output is correct |
22 |
Correct |
812 ms |
14292 KB |
Output is correct |
23 |
Correct |
825 ms |
14540 KB |
Output is correct |
24 |
Correct |
771 ms |
14540 KB |
Output is correct |
25 |
Correct |
828 ms |
14628 KB |
Output is correct |
26 |
Correct |
793 ms |
14540 KB |
Output is correct |
27 |
Correct |
822 ms |
14544 KB |
Output is correct |
28 |
Correct |
838 ms |
14548 KB |
Output is correct |
29 |
Correct |
841 ms |
14544 KB |
Output is correct |
30 |
Correct |
735 ms |
14540 KB |
Output is correct |