怎么会TLE?帮忙康康怎么优化?
查看原帖
怎么会TLE?帮忙康康怎么优化?
213218
蒟蒻CGZ楼主2020/7/22 19:05

rt

multiset打的,超时了#8 #9 #10 #12

#include <bits/stdc++.h>
using namespace std;
multiset<int> q;
int n;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	while(n -- ) {
		int opt, x;
		cin >> opt >> x;
		if(opt == 1) {
			q.insert(x);
		}
		else if(opt == 2) {
			multiset<int>::iterator it = q.lower_bound(x);
			q.erase(it);
		}
		else if(opt == 3) {
			int num = 0;
			multiset<int>::iterator it = q.lower_bound(x);
			for (multiset<int>::iterator i = q.begin(); i != it; ++ i, ++ num);
			cout << num + 1 << endl;
		}
		else if(opt == 4) {
			int num = 1;
			for (multiset<int>::iterator i = q.begin(); i != q.end(); ++ i, ++ num)
				if(num == x) {
					cout << *i << endl;
					break;
				}
		}
		else if(opt == 5) {
			multiset<int>::iterator it = q.lower_bound(x);
			-- it;
			cout << *it << endl;
		}
		else {
			multiset<int>::iterator it = q.upper_bound(x);
			cout << *it << endl;
		}
	}
	return 0;
}
2020/7/22 19:05
加载中...