QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461319 | #3101. Event Hopping 2 | AmrT | 0 | 27ms | 12268kb | C++23 | 3.3kb | 2024-07-02 17:55:14 | 2024-07-02 17:55:15 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define lop(i, n) for(ll i = 0; i < (ll)n; i++)
#define in(v) for(auto &i: v) cin >> i;
#define alop(i,v) for(auto &i: v)
#define ll long long
#define ld long double
#define endl '\n'
#define all(v) v.begin(),v.end()
#define mem(dp, x) memset(dp, x, sizeof(dp))
#define sq(x) ((x) * (x))
#define pb push_back
using namespace std;
struct node{
ll mn = 1e18, ind = 1e18;
friend node operator+(node a, node b){
if(a.mn <= b.mn)
return a;
else
return b;
}
};
struct segtree{
ll s, e;
vector<node> tree;
void init(ll n){
ll nxt2 = 1 << (__lg(n - 1) + 1);
s = nxt2 - 1, e = nxt2 * 2 - 2;
tree.resize(nxt2 * 2 - 1);
}
void update(ll index, ll value){
index += s;
tree[index] = {value, index};
while(index){
index = index / 2 - !(index & 1);
tree[index] = tree[index * 2 + 1] + tree[index * 2 + 2];
}
}
node get(ll x, ll lx, ll rx, ll r){
ll mid = (lx + rx) / 2;
if(rx <= r)
return tree[x];
else if(r < lx)
return {(ll)1e18, (ll)1e18};
else
return get(x * 2 + 1, lx, mid, r) + get(x * 2 + 2, mid + 1, rx, r);
}
ll get(ll r){
node ans = get(0, s, e, r + s);
if(ans.mn != 1e18) return ans.ind - s;
return 1e18;
}
ll arr(ll ind){return tree[ind + s].mn;}
};
ll bs(vector<pair<ll, ll>> &arr, ll x){
ll l = 0, r = arr.size() - 1, mid, ans = 1e18;
while(l <= r){
mid = (l + r) / 2;
if(arr[mid].first <= x)
ans = mid, l = mid + 1;
else
r = mid - 1;
}
return ans;
}
bool cmp(vector<pair<ll, ll>> a, vector<pair<ll, ll>> b){
lop(i, a.size()){
if(a[i] < b[i])
return 1;
else if(a[i] > b[i])
return 0;
}
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, k; cin >> n >> k;
vector<pair<ll, ll>> arr(n); //{r, l}
map<pair<ll, ll>, ll> mp;
lop(i, n){
ll a, b; cin >> a >> b;
arr[i] = {b, a};
mp[{b, a}] = i;
}
sort(all(arr));
vector<segtree> dp(k + 1);
ll par[k + 1][n] = {}; mem(par, -1);
dp[1].init(n);
lop(i, n){
dp[1].update(i, arr[i].second), par[1][i] = i;
}
for(int i = 2; i <= k; i++){
dp[i].init(n);
lop(j, n){
ll res = bs(arr, arr[j].second);
if(res == 1e18) continue;
ll g = dp[i - 1].get(res);
if(g == 1e18) continue;
par[i][j] = g;
dp[i].update(j, arr[j].second);
}
}
vector<vector<pair<ll, ll>>> sol;
lop(i, n){
ll g = dp[k].arr(i);
if(g == 1e18) continue;
vector<pair<ll, ll>> temp = {{arr[i].second, mp[arr[i]]}};
ll j = k, ind = i;
while(par[j][ind] != ind){
ind = par[j][ind], j--;
temp.pb({arr[ind].second, mp[arr[ind]]});
}
reverse(all(temp));
sol.pb(temp);
}
sort(all(sol), cmp);
if(sol.empty()) cout << -1;
else
lop(i, k) cout << sol[0][i].second + 1 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 7
Accepted
time: 1ms
memory: 3860kb
input:
1 1 1 3
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 1 2 4 3 7
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
3 1 2 5 3 5 4 7
output:
1
result:
ok single line: '1'
Test #4:
score: -7
Memory Limit Exceeded
input:
99999 93097 40044 40749 44538 45365 46530 47401 52845 53481 59519 60065 86226 87059 88353 88992 95665 96502 95669 96575 100446 100968 121870 122544 130836 131540 146294 147230 151177 151970 160381 161376 164174 165119 166582 167438 169062 169687 173200 173849 177329 178217 189213 189811 249372 25029...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #47:
score: 1
Accepted
time: 0ms
memory: 3600kb
input:
1 1 134842099 137944073
output:
1
result:
ok single line: '1'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 2 4015595 884953730 519508315 726912949
output:
-1
result:
ok single line: '-1'
Test #49:
score: -1
Wrong Answer
time: 0ms
memory: 3632kb
input:
3 2 551691302 800582045 14063803 52897269 153641504 567834643
output:
2 3
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #3:
score: 0
Wrong Answer
Test #74:
score: 0
Wrong Answer
time: 27ms
memory: 12268kb
input:
3000 57 226083340 261990234 392684356 462929590 468018811 841719892 495096853 606046097 196983814 256423598 331199122 967656486 802593662 931108452 74501453 679054962 294344294 752837262 295708332 547261648 265421699 652708933 272959087 727136240 165667761 846917534 61770748 157663302 608516043 8492...
output:
766 327 2952 2445 2004 660 1811 2645 2798 990 2282 1562 1670 2742 2881 1611 2867 665 257 2593 2608 2592 1774 2490 2873 1440 1968 1226 1316 85 2416 2005 1597 1231 1850 1676 543 971 850 903 2103 2632 173 2481 1508 104 1074 928 2503 2690 686 1712 697 2718 411 2540 811
result:
wrong answer 1st lines differ - expected: '50', found: '766'
Subtask #4:
score: 0
Time Limit Exceeded
Test #111:
score: 0
Time Limit Exceeded
input:
100000 361 136798318 785362988 255943758 535488232 175203444 266819907 766993466 893575347 67274251 589651108 662289594 883406317 830803801 849703610 729398668 798198453 202605534 677648797 66407931 925909114 174421361 601553812 522629146 701284080 136544340 295925673 299796891 499869765 736583725 8...