QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#874687#8613. CardinalityCoffins#TL 0ms0kbC++203.0kb2025-01-28 13:39:502025-01-28 13:39:50

Judging History

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

  • [2025-01-28 13:39:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2025-01-28 13:39:50]
  • 提交

answer

#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
#define beg begin
#define All(A) A.beg(),A.end()
#define pb push_back
#define fst first
#define sec second
#define gr greater<>()
#define Lsh(A) sort(All(A)),\
A.erase(unique(All(A)),A.end());
#define u_set unordered_set
#define u_map unordered_map
#define lwb lower_bound
#define upb upper_bound
using ull=unsigned long long;
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
using vi=vector<int>;
using gi=greater<int>;
using str=string;
using bqi=priority_queue<int>;
using lqi=priority_queue<int,vi,gi>;
using qi=queue<int>;
using si=set<int>;
using usi=u_set<int>;
using vll=vector<ll>;
using pll=pair<ll,ll>;
using vvi=vector<vi>;
using vvl=vector<vll>;
using vpi=vector<pii>;
int n,m,q;
namespace sub1{
const int N=201;
const int M=1e5+1;
using bst=bitset<M>;
bst bs[N][N];int a[N];
void upd(int c)
{
    for(int i=1;i<n;i++)
    bs[a[i]][a[i+1]][c]=1;
}
void solve()
{
    for(int i=1;i<=n;i++)a[i]=i;upd(0);
    for(int i=1;i<=m;i++)
    {
        int x,y;cin>>x>>y;
        swap(a[x],a[y]),upd(i);
    }for(int i=1;i<=q;i++)
    {
        int k;cin>>k;bst rs;rs=~rs;
        for(int i=1;i<=k;i++)cin>>a[i];
        for(int i=1;i<k;i++)
        rs&=bs[a[i]][a[i+1]];
        cout<<rs._Find_first()<<'\n';
    }
}
}
namespace sub2{
const int N=1e5+5;
int a[N],x[N],y[N],k[N];
vi qr[N];u_map<int,u_map<int,vi> > vec;
u_map<int,int> ps[N];
int rs[N],vl[N];
void del(int x,int v,int o)
{
    if(x>1&&a[x-1]>0)
    {
        for(int id:vec[a[x-1]][v])
        vl[id]--;
    }if(x<n&&a[x+1]>0)
    {
        for(int id:vec[v][a[x+1]])
        vl[id]--;
    }a[x]=-1;
}
void ins(int x,int v,int o)
{
    if(x>1&&a[x-1]>0)
    {
        vi nv;
        for(int id:vec[a[x-1]][v])
        {
            vl[id]++;if(vl[id]==k[id]-1)
            rs[id]=o;else nv.pb(id);
        }vec[a[x-1]][v]=nv;
    }if(x<n&&a[x+1]>0)
    {
        vi nv;
        for(int id:vec[v][a[x+1]])
        {
            vl[id]++;if(vl[id]==k[id]-1)
            rs[id]=o;else nv.pb(id);
        }vec[v][a[x+1]]=nv;
    }a[x]=v;
}
void solve()
{
    for(int i=1;i<=m;i++)cin>>x[i]>>y[i];
    for(int i=1;i<=q;i++)
    {
        cin>>k[i];qr[i].resize(k[i]);
        for(int j=0;j<k[i];j++)
        cin>>qr[i][j],ps[i][qr[i][j]]=j;
        for(int j=0;j+1<k[i];j++)
        vec[qr[i][j]][qr[i][j+1]]
        .pb(i);rs[i]=m+1;
    }for(int i=1;i<=n;i++)a[i]=-1;
    for(int i=1;i<=n;i++)ins(i,i,0);
    for(int i=1;i<=m;i++)
    {
        int x=sub2::x[i],y=sub2::y[i];
        int vx=a[x],vy=a[y];
        del(x,vx,i),del(y,vy,i);
        ins(x,vy,i),ins(y,vx,i);
    }for(int i=1;i<=q;i++)
    cout<<rs[i]<<'\n';
}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m>>q;
    if(n<=200)sub1::solve();
    else sub2::solve();
    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

4 5
1 2
2 3
5 6
6 7
4 7

output:


result: