85pts 2RE + 1WA 求调!
查看原帖
85pts 2RE + 1WA 求调!
463956
incra楼主2023/9/4 09:56

RT,代码如下:

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> PII;
const int dx[] = {1,-1,0,0},dy[] = {0,0,1,-1};
bool LAST = false;
istream& operator >> (istream& in,char* s) {
    if (LAST) exit (0);
	char ch = cin.get ();
	while ((isspace (ch) || ch == '\n') && ch != EOF) ch = cin.get ();
	int n = 0;
	while (!(isspace (ch) || ch == '\n') && ch != EOF) s[n++] = ch,ch = cin.get ();
	s[n] = '\0';
	if (ch == EOF) LAST = true;
	return in;
}
const int N = 200010;
int n;
int a[N],sum[N];
int hh = 1,tt = 0;
int del_cnt;
multiset <int> s;
int main () {
	cin >> n >> n;
	while (n--) {
		int op;
		cin >> op;
		if (op == 1) {
			int x;
			cin >> x;
			s.insert (x);
			a[++tt] = x;
			sum[tt] = sum[tt - 1] + x;
		}
		else if (op == 2) {
			int x;
			cin >> x;
			del_cnt += x;
			while (hh <= tt && sum[hh] <= del_cnt) {
				s.erase (s.find (a[hh]));
				hh++;
			}
		}
		else if (op == 3) {
			int x;
			cin >> x;
			int z = x + del_cnt;
			int pos = lower_bound (sum + hh,sum + tt + 1,z) - sum - 1;
			cout << z - sum[pos] << endl;
		}
		else cout << *s.rbegin () << endl;
	}
	return 0;
}

貌似是第 4 个操作 RE 了

2023/9/4 09:56
加载中...