結果
問題 | No.2077 Get Minimum Algorithm |
ユーザー | 👑 Nachia |
提出日時 | 2022-09-16 21:39:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 425 ms / 3,000 ms |
コード長 | 2,832 bytes |
コンパイル時間 | 1,040 ms |
コンパイル使用メモリ | 84,980 KB |
実行使用メモリ | 80,636 KB |
最終ジャッジ日時 | 2024-12-21 18:40:51 |
合計ジャッジ時間 | 12,924 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
19,712 KB |
testcase_01 | AC | 24 ms
19,840 KB |
testcase_02 | AC | 25 ms
19,712 KB |
testcase_03 | AC | 26 ms
19,840 KB |
testcase_04 | AC | 30 ms
19,840 KB |
testcase_05 | AC | 28 ms
19,840 KB |
testcase_06 | AC | 26 ms
19,840 KB |
testcase_07 | AC | 28 ms
19,968 KB |
testcase_08 | AC | 28 ms
19,712 KB |
testcase_09 | AC | 29 ms
19,840 KB |
testcase_10 | AC | 27 ms
19,840 KB |
testcase_11 | AC | 30 ms
19,968 KB |
testcase_12 | AC | 413 ms
80,504 KB |
testcase_13 | AC | 420 ms
80,636 KB |
testcase_14 | AC | 404 ms
80,508 KB |
testcase_15 | AC | 406 ms
80,508 KB |
testcase_16 | AC | 425 ms
80,636 KB |
testcase_17 | AC | 422 ms
80,632 KB |
testcase_18 | AC | 418 ms
80,508 KB |
testcase_19 | AC | 409 ms
80,628 KB |
testcase_20 | AC | 408 ms
80,504 KB |
testcase_21 | AC | 417 ms
80,504 KB |
testcase_22 | AC | 316 ms
80,400 KB |
testcase_23 | AC | 319 ms
80,504 KB |
testcase_24 | AC | 323 ms
80,632 KB |
testcase_25 | AC | 304 ms
80,500 KB |
testcase_26 | AC | 298 ms
80,504 KB |
testcase_27 | AC | 377 ms
80,500 KB |
testcase_28 | AC | 264 ms
50,160 KB |
testcase_29 | AC | 145 ms
25,856 KB |
testcase_30 | AC | 255 ms
80,628 KB |
testcase_31 | AC | 225 ms
50,032 KB |
testcase_32 | AC | 143 ms
25,856 KB |
testcase_33 | AC | 239 ms
80,556 KB |
testcase_34 | AC | 172 ms
50,028 KB |
testcase_35 | AC | 110 ms
25,856 KB |
testcase_36 | AC | 303 ms
80,632 KB |
testcase_37 | AC | 276 ms
80,504 KB |
testcase_38 | AC | 26 ms
19,712 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <atcoder/modint> using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) using Modint = atcoder::static_modint<998244353>; int SegN = 1<<18; struct PersistentSegtreeNode{ PersistentSegtreeNode *l; PersistentSegtreeNode *r; int sum; static PersistentSegtreeNode* up( PersistentSegtreeNode* l, PersistentSegtreeNode* r ){ PersistentSegtreeNode* res = new PersistentSegtreeNode(); res->l = l; res->r = r; res->sum = l->sum + r->sum; return res; } }; PersistentSegtreeNode* nodeSeg(int val){ PersistentSegtreeNode* res = new PersistentSegtreeNode(); res->l = res->r = nullptr; res->sum = val; return res; } PersistentSegtreeNode* initSeg(int a, int b){ if(b-a == 1) return nodeSeg(0); int mid = (a + b) / 2; return PersistentSegtreeNode::up(initSeg(a, mid), initSeg(mid, b)); } PersistentSegtreeNode* setSeg( PersistentSegtreeNode* p, int pos, int val, int a = -1, int b = -1 ){ if(a == -1){ a = 0; b = SegN; } assert(a <= pos); assert(pos < b); if(b-a == 1) return nodeSeg(val); int mid = (a + b) / 2; if(pos < mid){ return PersistentSegtreeNode::up( setSeg(p->l, pos, val, a, mid), p->r ); } else{ return PersistentSegtreeNode::up( p->l, setSeg(p->r, pos, val, mid, b) ); } } int main(){ int N; cin >> N; vector<int> P(N); rep(i,N) cin >> P[i]; vector<int> I(N); rep(i,N) I[P[i]-1] = i; vector<PersistentSegtreeNode*> seg; seg.push_back(initSeg(0, SegN)); rep(i,N) seg.push_back(setSeg(seg.back(), I[i], 1)); int Q; cin >> Q; rep(i,Q){ int u,v; cin >> u >> v; int x = v-1; int a = 0, b = SegN; vector<pair<PersistentSegtreeNode*, int>> T; T.push_back({ seg[v], 1 }); while(b-a > 1){ int m = (a+b) / 2; int tmp = 0; for(auto& Tn : T){ auto q = Tn.first; auto w = Tn.second; tmp += q->l->sum * w; } if(tmp <= u){ a = m; for(auto& Tn : T) Tn.first = Tn.first->r; u -= tmp; } else{ b = m; for(auto& Tn : T) Tn.first = Tn.first->l; } } int ans = max(a, I[x]) + 1; cout << ans << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;