补了差不多5个题,先把4个题的题解先写了。。。我感觉再不写,过几天更不会写了。。。
男神的演唱会 XDOJ 1060
题目链接
http://acm.xidian.edu.cn/problem.php?id=1160
题解
每个人每个时间段都有一个可能的不同状态,可能在也可能不在,对于每个询问,我们维护当前在听演唱会的这么一个人的集合,在线查询的,按照时间,依次往后推移。
代码
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<string>
#include<cctype>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef struct qz
{
int flag;
int num,time;
};
bool cmp(const qz &a,const qz &b)
{
return a.time<b.time;
}
qz s[1000005];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&s[i].flag,&s[i].time,&s[i].num);
}
sort(s,s+n,cmp);
set<int>ss;
int j=0;
for(int i=0;i<m;i++)
{
int z,zz;
scanf("%d%d",&z,&zz);
while(s[j].time<z&&j<n)
{
if(s[j].flag==1){ss.insert(s[j].num);}
else ss.erase(s[j].num);
j++;
}
if(ss.