結果
| 問題 |
No.2809 Sort Query
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2024-07-12 23:38:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,240 bytes |
| コンパイル時間 | 6,326 ms |
| コンパイル使用メモリ | 336,356 KB |
| 実行使用メモリ | 79,264 KB |
| 最終ジャッジ日時 | 2024-07-12 23:39:13 |
| 合計ジャッジ時間 | 17,000 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 1 -- * 69 |
ソースコード
#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; }
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]]);
//cout << a[i] << " " << trans[a[i]] << " " << get << endl;
seg.set(trans[a[i]], get + 1);
}
//rep(i, sz) {
// cout << seg.get(i) << " ";
//}cout << endl;
for (; i < q;) {
map<int, int>mp;//index,compValue
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;
}
kwm_t