微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

题解 Emotional Flutter

传送门

因为一个等号挂掉了10pts

发现每个黑色段一定对应了一段不可行的出发区间
检查是否存在所有黑色段的并集的补集即可

具体来说,我们对于每个黑色段计算出一个(有的是两个)区间 \([l, r]\) ,把它们全合并,看有没有剩下的位置

Code:

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 500010
#define ll long long 
//#define int long long 

char buf[1<<21], *p1=buf, *p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1<<21, stdin)), p1==p2?EOF:*p1++)
inline int read() {
	int ans=0, f=1; char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-f; c=getchar();}
	while (isdigit(c)) {ans=(ans<<3)+(ans<<1)+(c^48); c=getchar();}
	return ans*f;
}

int n; ll s, k;
ll a[N];

namespace force{
	bool lim[N]; ll ento;
	bool check(int b) {
		ll Now=b;
		while (Now<ento) {
			Now+=k;
			if (lim[Now]) return 0;
		}
		return 1;
	}
	void solve() {
		ento=0;
		memset(lim, 0, sizeof(lim));
		for (int i=1; i<=n; ++i) {
			//cout<<"goto lim: "<<ento+1<<' '<<ento+a[i]+s<<endl;
			if (i&1) for (int j=ento+1; j<ento+a[i]+s; ++j) lim[j]=1;
			ento+=a[i];
		}
		//cout<<"lim: "; for (int i=0; i<=ento; ++i) cout<<lim[i]<<' '; cout<<endl;
		//cout<<"check: "; for (int i=0; i<=k; ++i) cout<<check(-i)<<' '; cout<<endl;
		for (int i=0; i<=k; ++i)
			if (check(-i)) {puts("TAK"); return ;}
		puts("NIE");
	}
}

namespace task1{
	struct range{ll l, r; inline void build(ll a, ll b) {l=a; r=b;}}ran[N];
	inline bool operator < (range a, range b) {return a.l<b.l;}
	void solve() {
		ll Now=0; int top=0;
		for (int i=1; i<=n; ++i) {
			if (i&1) {
				if (1ll*a[i]+s>k) {puts("NIE"); return ;}
				//cout<<"limit: "<<Now+1<<' '<<Now+a[i]+s-1<<endl;
				ll t1=ceil((1.0*Now+1)/(1.0*k)+1e-8);
				ran[++top].build(Now+1-t1*k, Now+a[i]+s-1-t1*k);
				if (Now+a[i]+s-1-t1*k>=0) {
					++t1;
					ran[++top].build(Now+1-t1*k, Now+a[i]+s-1-t1*k);
				}
			}
			Now+=a[i];
		}
		sort(ran+1, ran+top+1);
		//cout<<"ran: "<<endl; for (int i=1; i<=top; ++i) cout<<ran[i].l<<' '<<ran[i].r<<endl;
		for (int i=2; i<=top; ++i) {
			//cout<<"i: "<<i<<endl;
			if (ran[i-1].r+1>=ran[i].l) ran[i].l=ran[i-1].l, ran[i].r=max(ran[i-1].r, ran[i].r);
			else {puts("TAK"); return ;}
		}
		//assert(top==1);
		//cout<<"top: "<<ran[top].l<<' '<<ran[top].r<<endl;
		if ((ran[top].l>=-k&&ran[top].r<-1) || (ran[top].l>-k&&ran[top].r<0)) {puts("TAK"); return ;}
		puts("NIE");
	}
}

signed main()
{
	int T;
	
	T=read();
	while (T--) {
		s=read(); k=read(); n=read();
		for (int i=1; i<=n; ++i) a[i]=read();
		//force::solve();
		task1::solve();
	}
	
	return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐