QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#762310#1286. Ternary String CountingThe_Shadow_DragonRE 0ms0kbC++142.2kb2024-11-19 14:34:542024-11-19 14:34:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-19 14:34:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-19 14:34:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long
#define sort stable_sort 
#define endl '\n'
const int p=1000000007;
int s[5010];
deque<int>f,idx,idy,lie[5010],hang[5010];
deque<pair<int,int> >q[5010];
void insert(int x,int y,int val)
{
	if(val!=0)
	{
		lie[x].push_back(f.size());
		hang[y].push_back(f.size());
		f.push_back(val);
		idx.push_back(x);
		idy.push_back(y);
		s[x]=(s[x]+val)%p;
		s[y]=(s[y]+val)%p;
	}
}
int qpow(int a,int b,int p)
{
	int ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=1ll*ans*a%p;
		}
		b>>=1;
		a=1ll*a*a%p;
	}
	return ans;
}
int main()
{
#define Isaac
#ifdef Isaac
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
#endif
	int t,n,m,l,r,x,lj,rj,lk,rk,ans,inv=qpow(2,p-2,p),i,j,k,v;
	scanf("%d",&t);
	for(v=1;v<=t;v++)
	{
		cin>>n>>m;
		ans=0;
		f.clear();
		idx.clear();
		idy.clear();
		for(i=0;i<=n;i++)
		{
			lie[i].clear();
			hang[i].clear();
			q[i].clear();
			s[i]=0;
		}
		for(i=1;i<=m;i++)
		{	
			cin>>l>>r>>x;
			q[r].push_back(make_pair(l,x));
		}
		insert(0,0,3);
		for(i=1;i<=n;i++)
		{
			lj=lk=0;
			rj=rk=0x3f3f3f3f;
			for(j=0;j<q[i].size();j++)
			{
				switch(q[i][j].second)
				{
					case 1:
						rj=min(rj,q[i][j].first-1);
						break;
					case 2:
						lj=max(lj,q[i][j].first);
						rk=min(rk,q[i][j].first-1);
						break;
					case 3:
						lk=max(lk,q[i][j].first);
						break;
					default:
						break;
				}
			}
			for(j=0;j<=i;j++)
			{
				if(j<lj||j>rj)
				{
					for(k=0;k<lie[j].size();k++)
					{
						s[idx[lie[j][k]]]=(s[idx[lie[j][k]]]-f[lie[j][k]]+p)%p;
						s[idy[lie[j][k]]]=(s[idy[lie[j][k]]]-f[lie[j][k]]+p)%p;
						f[lie[j][k]]=0;
					}
					lie[j].clear();
				}
				if(j<lk||j>rk)
				{
					for(k=0;k<hang[j].size();k++)
					{
						s[idx[hang[j][k]]]=(s[idx[hang[j][k]]]-f[hang[j][k]]+p)%p;
						s[idy[hang[j][k]]]=(s[idy[hang[j][k]]]-f[hang[j][k]]+p)%p;
						f[hang[j][k]]=0;
					}
					hang[j].clear();
				}	
			}
			if(i!=n)
			{
				for(j=i;j>=0;j--)
				{
					insert(i,j,s[j]);
				}
			}
		}
		for(i=0;i<=n;i++)
		{
			ans=(ans+s[i])%p;
		}
		cout<<1ll*ans*inv%p<<endl;
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

4
1 0
2 0
3 0
5 2
1 3 3
4 5 1

output:


result: