这题卡常卡得有点丧心病狂了
查看原帖
这题卡常卡得有点丧心病狂了
422684
M1saka16I72楼主2024/11/10 13:16

卡了一上午都没过,最高 75pts。

复杂度是对的,O(lmaxr)\mathcal{O}(\sum l\max r),求卡常。

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mp_ make_pair
#define pb_ push_back
#define pob_ pop_back
#define fst first
#define snd second
#define debug cout<<"********\n";
#define reset(x,y) memset(x,y,sizeof(x))
#define fi(x) freopen(x,"r",stdin)
#define fo(x) freopen(x,"w",stdout)
#define iosf ios::sync_with_stdio(0);cin.tie(0);
#define prec(x) cout<<setprecision(x);
#define prec0(x) cout<<fixed<<setprecision(x);
#define Misaka16172 sb
#define kamisako femboy

using ll = long long;
using ld = long double;
using db = double;
using ull = unsigned long long;
using uint = unsigned int;

constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ull mod1 = 1e9+7,mod9 = 998244353;

using namespace std;

#define getchar getchar_unlocked
#define putchar putchar_unlocked

template <class T>
inline void read(T &x){
    x = 0;T w = 1;
    char c = 0;
    while(!isdigit(c)){
        if(c=='-')  w = -1;
        c = getchar();
    }
    while(isdigit(c)){
        x = ((x<<3)+(x<<1))+c-'0';
        c = getchar();
    }
    x = x*w;
}
template<class T,typename ...Args>
inline void read(T &x,Args &...rest){read(x);read(rest...);}

template<class T>
inline void write(T x){
    if(!x)  return putchar('0'),void();
    else if(x<0) putchar('-'),x*=-1;
    int st[40],t = 0;
    while(x){st[++t] = x%10,x/=10;}
    while(t){putchar(st[t--]+'0');}
}

template <class T>
inline string bin(T x,int d = 0){return (((d>1)||(x>>1))?bin(x>>1,d-1):"")+to_string(x&1);}

int Test = 1,Case = 1;

constexpr int N = 2e5+5,T = 102;

int c[N],vis[N],lst[N],n,k,q;
bool ans[N],f[N],g[N];
int a[N],bel[N],L[N],R[N];

struct Query{
	int r,c,id;
	inline bool operator <(const Query &x)const{return r<x.r;}
}Q[N];

vector<vector<int>> p;

inline void add(int l,int r){
	if(l>r)	return;
	c[l]++,c[r+1]--;
}

void solve(){
	read(n,k,q);
	p = vector<vector<int>>(N);
	int cnt = 1;
	for(int i=1;i<=n;i++){
		int l;read(l);
		L[i] = cnt;
		for(int j=1;j<=l;j++,cnt++)	read(a[cnt]),bel[cnt] = i,R[i] = cnt,p[a[cnt]].pb_(cnt);
	}
	for(int i=1;i<=q;i++)	read(Q[i].r,Q[i].c),Q[i].id = i;
	sort(Q+1,Q+1+q);
	reset(c,0),reset(ans,0);
	for(int i=0,t=1;i<=100;i++){
		if(Q[t].r==i)	reset(g,0);
		for(int j=1;j<=cnt;j++)	c[j]+=c[j-1],f[j] = (bool)c[j],g[a[j]]|=f[j];
		for(;t<=q && Q[t].r==i;t++)	ans[Q[t].id] = g[Q[t].c];
		if(t>q)	break;
		if(!i){
			for(int x:p[1])	add(x+1,min(R[bel[x]],x+k-1));
			continue;
		}
		if(i==100)	break;
		reset(c,0),reset(vis,0);
		for(int j=1;j<=cnt;j++){
			if(!f[j] || vis[a[j]]==2 || vis[a[j]]==1 && lst[a[j]]==bel[j])	continue;
			if(!vis[a[j]]){
				lst[a[j]] = bel[j];
				for(int x:p[a[j]]){
					if(bel[x]==bel[j])	continue;
					add(x+1,min(R[bel[x]],x+k-1));
				}
			}
			else{
				auto it = lower_bound(p[a[j]].begin(),p[a[j]].end(),L[lst[a[j]]]);
				for(;it!=p[a[j]].end() && *it<=R[lst[a[j]]];it++)	add(*it+1,min(R[bel[*it]],*it+k-1));
			}
			vis[a[j]]++;
		}
	}
	for(int i=1;i<=q;i++)	putchar('0'+ans[i]),putchar('\n');
}

int main(){
    read(Test);
    for(;Case<=Test;++Case) solve();
    return 0;
}
2024/11/10 13:16
加载中...