调了2个小时了!!都快要成题解了,0pts?TLE+RE?
查看原帖
调了2个小时了!!都快要成题解了,0pts?TLE+RE?
520544
Phrvth楼主2023/3/11 18:14

Code:

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 7, MAX = 2e6 + 10;
#define pyl 1e6 + 10

int n, kt[MAXN], tp, ans, vis[MAXN], k[MAXN];

int c1[MAX+7], c2[MAX+7];

#define lb(i)(i & -i)

inline void modify(int x, int y, int c[]) {
	for (x; x <= MAX; x += lb(x)) c[x] += y;
} 
inline int query(int x, int c[]) {
	int ans = 0;
	for (; x; x -= lb(x)) ans += c[x];
	return ans;
}

int main () {
//	freopen("cin.in", "r", stdin);
//	freopen("cout.out", "w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		string s;
		cin >> s;
		if (s == "Add") {
			int x, y, z;
			cin >> x >> y >> z;
			if (x == 0) {
				if (y - z > 0) kt[++ tp] = 3, ans ++;//恒成立
				else kt[++ tp] = 0;//恒不成立 
			} else if (x < 0) { //x<k 1 c2
				k[++ tp] = ceil((z * 1.0 - y) / x) + pyl;
				if (k[tp] > 1e6) kt[tp] = 3, ans ++;//恒成立 
				else if (k[tp] < -1e6) kt[tp] = 0;
				else kt[tp] = 1, modify(k[tp] + pyl, 1, c2);
			} else if (x > 0) { //x>k 2 c1
				k[++ tp] = floor((z * 1.0 - y) / x) + pyl;
				if (k[tp] > 1e6) kt[tp] = 0;
				else if (k[tp] < -1e6) kt[tp] = 3, ans ++;
				else kt[tp] = 2, modify(k[tp] + pyl, 1, c1);
			}
		} else if (s == "Del") {
			int x;
			cin >> x;
			if (vis[x]) continue;
			vis[x] = 1;
			if (kt[x] == 3) ans --;
			else if (kt[x] == 1) modify(k[x], -1, c2);
			else if (kt[x] == 2) modify(k[x], -1, c1);
		} else if (s == "Query") {
			int x;
			cin >> x;
			cout << (query(x - 1 + pyl, c1) + (query(MAX, c2) - query(x + pyl, c2)) + ans) << "\n";
		}
	}
	return 0;
}
2023/3/11 18:14
加载中...