跳到正文

个人记录

永远的UKE代码

yky_zsx约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年8月28日
收录
2025年12月21日
更新
2026年11月17日
篇幅
约 1 分钟

版本

  1. v1当前

P9853 [入门赛 #17] 方程求解

UKE小代码:

C++
#include<bits/stdc++.h>
using namespace std;
long long a[200005],b[200005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		long long x,y,z;
		char s,ss,sss;
		cin>>x>>s>>ss>>y>>sss>>z;
		if(ss=='+'){
			z-=y;
		}else if(ss=='-'){
			z+=y;
		}
		z/=x;
		a[i]=z;
        b[a[i]]=1;
	}
	for(int i=1;i<=m;i++){
		long long l,r,sum=0;
		cin>>l>>r;
        for(int k=1;k<=n;k++){
            b[a[k]]=1;
        }
		for(int k=1;k<=n;k++){
			for(int j=l;j<=r;j++){
				if(a[k]==j&&b[a[k]]!=0){
					sum++;
                    b[a[k]]=0;
				}
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
原文