結果

問題 No.2809 Sort Query
ユーザー kwm_tkwm_t
提出日時 2024-07-12 23:41:50
言語 C++23
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1,685 ms
57,808 KB
testcase_42 AC 1,621 ms
57,896 KB
testcase_43 AC 1,704 ms
57,900 KB
testcase_44 AC 1,663 ms
59,392 KB
testcase_45 AC 1,698 ms
57,900 KB
testcase_46 AC 1,228 ms
57,668 KB
testcase_47 AC 1,246 ms
57,812 KB
testcase_48 AC 1,252 ms
58,024 KB
testcase_49 AC 1,175 ms
57,884 KB
testcase_50 AC 1,308 ms
57,896 KB
testcase_51 AC 899 ms
57,892 KB
testcase_52 AC 814 ms
57,800 KB
testcase_53 AC 855 ms
57,824 KB
testcase_54 AC 887 ms
57,888 KB
testcase_55 AC 874 ms
57,896 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 TLE -
testcase_62 WA -
testcase_63 WA -
testcase_64 TLE -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0