MnZn 求助
查看原帖
MnZn 求助
218188
ParanoidMO楼主2022/10/27 17:31

本地样例4WA,交上去全RE,哪里错了呜呜呜

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+10;
const double g = 9.8;
int n, m, yc, ind;
int a[maxn], tree[maxn*4], tag[maxn*4], num[maxn];
struct node{
	int x, y, v;
	bool operator < (const node u) const{
		return y < u.y;
	}
} mis[maxn];
struct node1{
	double p1, p2;
	int p, ref1, ref2;
	bool operator < (const node1 u) const{
		return p1 < u.p1;
	}
};
struct node2{
	double p1, p2;
	int p, ref1, ref2;
	bool operator < (const node2 u) const{
		return p2 < u.p2;
	}
};
vector<node1> lst[maxn];
vector<node2> tmp;

int ls(int x) {return x*2;}
int rs(int x) {return x*2+1;}
int push_up(int p) {tree[p] = tree[ls(p)]+tree[rs(p)];}
void push_down(int l, int r, int p){
	tag[ls(p)] += tag[p];
	tag[rs(p)] += tag[p];
	int mid = (l+r)/2;
	tree[ls(p)] += tag[p]*(mid-l+1);
	tree[rs(p)] += tag[p]*(r-mid);
	tag[p] = 0;
}

void build(int l, int r, int p){
	tag[p] = 0; 
	if (l == r){
		tree[p] = 0;
		return;
	}
	int mid = (l+r)/2;
	build(l, mid, ls(p));
	build(mid+1, r, rs(p));
	push_up(p);
}

int query(int l, int r, int al, int ar, int p){
	if (al <= l && r <= ar){
		return tree[p];
	}
	int mid = (l+r)/2, res=0;
	push_down(l, r, p);
	if (mid >= al) res += query(l, mid, al, ar, ls(p));
	if (mid < ar) res += query(mid+1, r, al, ar, rs(p));
	return res;
}

void update(int l, int r, int al, int ar, int p, int k){
	if (al <= l && r <= ar){
		tree[p] += (r-l+1)*k;
		tag[p] += k;
		return;
	}
	int mid = (l+r)/2;
	push_down(l, r, p);
	if (mid >= al)	update(l, mid, al, ar, ls(p), k);
	if (mid < ar)	update(mid+1, r, al, ar, rs(p), k);
	push_up(p);
} 

node2 cvt(node1 u){
	node2 t;
	t.p1 = u.p1; t.p2 = u.p2;
	t.ref1 = u.ref1; t.ref2 = u.ref2;
	t.p = u.p;
	return t;
}

bool cmp(int a, int b){
	return a > b;
}

int main(){
	ios::sync_with_stdio(false);
//	freopen("missile4.in", "r", stdin);
//	freopen("missile4.out", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>mis[i].x>>mis[i].y>>mis[i].v;
	for (int i=1; i<=n; i++) cin>>a[i];
	sort(mis+1, mis+1+n);
	for (int i=1; i<=n; i++){
		if (yc != mis[i].y){
			yc = mis[i].y;
			ind ++;
		}
		lst[ind].push_back({mis[i].x, mis[i].x + sqrt(2*mis[i].y/g)*mis[i].v, i});
//		cout<<"y: "<<yc<<" i:"<<lst[ind][lst[ind].size()-1].p<<endl;
	}
	for (int i=1; i<=ind; i++){
		sort(lst[i].begin(), lst[i].end());
		tmp.clear();
		for (int j=0; j<lst[i].size(); j++) {
			lst[i][j].ref1 = j+1;
			tmp.push_back(cvt(lst[i][j]));
		}
		sort(tmp.begin(), tmp.end());
		for (int j=0; j<tmp.size(); j++){
			tmp[j].ref2 = j+1;	
//			cout<<"i: "<<tmp[j].p<<" p1:"<<tmp[j].ref1<<" p2:"<<tmp[j].ref2<<endl;
		}
		build(1, tmp.size()+10, 1);
		for (int j=0; j<tmp.size(); j++){
			num[tmp[j].p] += query(1, tmp.size()+5, tmp[j].ref1, tmp.size(), 1);
			update(1, tmp.size()+5, tmp[j].ref1, tmp[j].ref1, 1, 1);
		}
		build(1, tmp.size()+10, 1);
		for (int j=tmp.size()-1; j>=0; j--){
			num[tmp[j].p] += query(1, tmp.size()+5, 1, tmp[j].ref1, 1);
			update(1, tmp.size()+5, tmp[j].ref1, tmp[j].ref1, 1, 1);
		}
	}
//	for (int i=1; i<=n; i++) cout<<num[i]<<" ";
//	cout<<endl;
	for (int i=1; i<=n; i++)	a[i] = min(a[i], num[i]);
	sort(a+1, a+1+n, cmp);
	int ans = 0;
	for (int i=1; i<=n; i++) ans += num[i];
	for (int i=1; i<=m; i++) ans -= a[i];
	cout<<ans<<endl;
//	system("pause");
}
2022/10/27 17:31
加载中...