結果
問題 |
No.2809 Sort Query
|
ユーザー |
![]() |
提出日時 | 2024-07-12 23:41:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,866 bytes |
コンパイル時間 | 5,799 ms |
コンパイル使用メモリ | 336,184 KB |
実行使用メモリ | 116,008 KB |
最終ジャッジ日時 | 2024-07-12 23:44:26 |
合計ジャッジ時間 | 114,776 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 47 TLE * 7 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template<typename T> std::pair<std::vector<T>, int> compression(std::vector<T>org) { auto copy = org; std::sort(copy.begin(), copy.end()); copy.erase(unique(copy.begin(), copy.end()), copy.end()); for (auto &e : org) { e = std::lower_bound(copy.begin(), copy.end(), e) - copy.begin(); } return { org,copy.size() }; } int op(int a, int b) { return a + b; } int e() { return 0; } int target; bool f(int v) { return v <= target; } // 時間管理 class TimeKeeperDouble { private: std::chrono::high_resolution_clock::time_point start_time_; double time_threshold_; double now_time_ = 0; public: TimeKeeperDouble(const double time_threshold) : start_time_(std::chrono::high_resolution_clock::now()), time_threshold_(time_threshold) {} void setNowTime() { auto diff = std::chrono::high_resolution_clock::now() - this->start_time_; this->now_time_ = std::chrono::duration_cast<std::chrono::microseconds>(diff).count() * 1e-3; } double getNowTime() const { return this->now_time_; } bool isTimeOver() const { return now_time_ >= time_threshold_; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector<long long>a(n); rep(i, n)cin >> a[i]; struct Query { int t; int k; long long x; Query(int t = -1, int k = -1, long long x = -1) :t(t), k(k), x(x) {} void output() { std::cout << t << " " << k << " " << x << endl; } }; vector<long long>nums; vector<Query>query(q); rep(i, q) { int t, k; long long x; cin >> t; if (1 == t) { cin >> k >> x, k--; nums.push_back(x); } else if (3 == t) { cin >> k, k--; } query[i] = Query(t, k, x); } int i = 0; for (; i < q;) { while (i < q && 2 != query[i].t) { if (3 == query[i].t) cout << a[query[i].k] << endl; else a[query[i].k] = query[i].x; i++; } break; } i++; rep(i, n) nums.push_back(a[i]); auto[comp, sz] = compression(nums); map<int, long long>inv; map<long long, int>trans; rep(i, nums.size()) { trans[nums[i]] = comp[i]; inv[comp[i]] = nums[i]; } segtree<int, op, e>seg(sz); rep(i, n) { auto get = seg.get(trans[a[i]]); seg.set(trans[a[i]], get + 1); } TimeKeeperDouble time_keeper = TimeKeeperDouble(1000); for (; i < q;) { map<int, int>mp;//index,compValue time_keeper.setNowTime(); if (time_keeper.isTimeOver())break; while (i < q && 2 != query[i].t) { int index = query[i].k; if (3 == query[i].t) { if (mp.count(index)) { auto ans = mp[index]; ans = inv[ans]; cout << ans << endl; } else { target = index; auto pos = seg.max_right<f>(0); auto ans = inv[pos]; cout << ans << endl; } } else { mp[index] = trans[query[i].x]; } i++; } vector<pair<int, int>>vec; for (auto[k, v] : mp) { target = k; auto index = seg.max_right<f>(0); vec.push_back({ index ,v }); } for (auto p : vec) { { auto get = seg.get(p.first); seg.set(p.first, get - 1); } { auto get = seg.get(p.second); seg.set(p.second, get + 1); } } } return 0; }