跳到正文

个人记录

8.10晚上综合测试总结

R_qT_SplayTree_Query约 7 分钟
原文
文章信息与版本

文章信息

发布
2025年8月11日
收录
2025年12月12日
更新
2026年10月13日
篇幅
约 7 分钟

版本

  1. v1当前

得分

100+100+100+40+50+100+0=490100+100+100+40+50+100+0=490

T4

死因:对于最后一个数没有考虑乘的情况,所以挂了 6060 分。

AC 代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;

string s;

int ans;

struct node{
	int a[100005],l;
	int top(){
		return a[l];
	}
	void push(int x){
		a[++l]=x;
	}
	void pop(){
		l--;
	}
	bool empty(){
		return l==0;
	}
	int size(){
		return l;
	}
}st,op;

char ch;

signed main(){
	cin.tie(0)->sync_with_stdio(false);
	cout.tie(0)->sync_with_stdio(false);
	cin>>s;
	s+='+';
	int l=s.length(),cnt=0;
	ch='+';
	for(int i=0;i<l;i++){
		if(s[i]>='0'&&s[i]<='9'){
			cnt=cnt*10+(s[i]-'0');
		}else{
			if(ch=='+')st.push(cnt%10000);
			else if(!st.empty()){
				int x=st.top();
				st.pop();
				int y=cnt;
				st.push((x*y)%10000);
			}
			ch=s[i];
			cnt=0;
		}
	}
	int ans=0;
	while(!st.empty())ans+=st.top(),st.pop(),ans%=10000;
	cout<<ans%10000;
	return 0;
}

T5

死因:排序(按照右端点从小到大写成了按照左端点从小到大)写错导致挂了 5050 分。

AC 代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;

int n;

struct node{
	int l,r;
}a[100005];

int l,r,ans;

bool cmp(node a,node b){
	return a.r>b.r;
}

signed main(){
	cin.tie(0)->sync_with_stdio(false);
	cout.tie(0)->sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].r;
	}
	sort(a+1,a+1+n,cmp);
	int l=a[1].l,r=a[1].r;
	for(int i=1;i<=n;i++){
		if(a[i].r>=l){
			r=max(a[i].r,r);
			l=min(a[i].l,l);
		}else{
			ans+=r-l+1;
			l=a[i].l,r=a[i].r;
		}
	}
	if(n==0)cout<<0;
	else cout<<ans+r-l+1;
	return 0;
}

T7

对于一辆车,我们需要算出它在什么时候超速,因此我们需要记录一个左端点 ll 和右端点 rr。

我们可以分类讨论:

  • 对于加速度 a=0a=0,只要它不是在最后一个点进入的,那么它的初速度大于限速一定就会超速,否则不超速。超速区间为它第一次被拍到的摄像头到 mm。

  • 对于加速度大于 00,只要它不是在最后一个点进入的,那么它初速度大于限速/加速度加到一段距离之后就会超速。超速区间为它第一个被拍到的摄像头到 mm。

  • 对于加速度小于 00,如果它进来的初速就小于等于限速,那么它一定不会超速。如果初速大于限速,就需要找到它最后一个超速的点,它的超速区间为进来的那个点到最后一个超速的点。

在上面我们就可以统计超速了多少车。这就是第一个答案。

然后,每辆车就可以抽象成一个区间,第二个答案就是所有区间内至少需要有一棵树的树的棵树。

这就是区间贪心的板子题。

AC 代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;

int t;
int n,m,L,V;
int p[1000005];

struct node{
	int l,r;
}s[2000005];

int d[2000005],v[2000005],a[2000005];

int nexp[1000005];

bool cmp(node a,node b){
	if(a.r==b.r)return a.l<b.l;
	return a.r<b.r;
}

signed main(){
	cin.tie(0)->sync_with_stdio(false);
	cout.tie(0)->sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++){
			cin>>d[i]>>v[i]>>a[i];
		}
		for(int i=1;i<=m;i++){
			cin>>p[i];
		}
		p[0]=-1,p[m+1]=1e6;
		int cnt=0;
		for(int i=1;i<=m+1;i++){
			int l=p[i-1],r=p[i];
			for(int j=l+1;j<=r;j++){
				nexp[j]=i;
			}
		}
		for(int i=1;i<=n;i++){
			if(d[i]>p[m])continue;
			if(a[i]==0){
				if(v[i]<=V)continue;
				int l=nexp[d[i]];
				s[++cnt]=node{l,m};
			}else if(a[i]>0){
				int l=0;
				if(v[i]>V)l=nexp[d[i]];
				else if(v[i]==V)l=nexp[d[i]+1];
				else{
					int S=floor((V*V-v[i]*v[i])*1.0/2/a[i]);
					S++;
					if(d[i]+S>p[m])l=m+1;
					else l=nexp[d[i]+S];
				}
				if(l<=m)s[++cnt]=node{l,m};
			}else{
				if(v[i]<=V)continue;
				int S=ceil((V*V-v[i]*v[i])*1.0/2/a[i]);
				S--;
				int l=nexp[d[i]];
				if(d[i]+S<p[l])continue;
				int r=0;
				if(d[i]+S>=p[m])r=m;
				else r=nexp[d[i]+S+1]-1;
				s[++cnt]=node{l,r};
			}
		}
		if(cnt==0){
			cout<<0<<" "<<m<<'\n';
			continue;
		}
		sort(s+1,s+1+cnt,cmp);
		int ans=1,last=s[1].r;
		for(int i=2;i<=cnt;i++){
			if(s[i].l>last){
				ans++;
				last=s[i].r;
			}
		}
		cout<<cnt<<" "<<m-ans<<'\n';
	}
	return 0;
}

The EndThe\ End

原文