QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560487#9155. 集合RDFZchenyy100 ✓913ms52184kbC++144.1kb2024-09-12 15:56:202024-09-12 15:56:21

Judging History

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

  • [2024-09-12 15:56:21]
  • 评测
  • 测评结果:100
  • 用时:913ms
  • 内存:52184kb
  • [2024-09-12 15:56:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long

using ll=long long;

#define MAXN 1000005

int n,m,q,l,r;
int a[MAXN],b[MAXN];
ll ql[MAXN],qr[MAXN];
ll ca[MAXN],cb[MAXN]; ll ha,hb;
ll mod=998244353,bas,b2;
ll bp[MAXN];
int rm[MAXN];
bool ans[MAXN];

ll fpow(ll a,ll b,ll p){
    ll res=1; for(;b;b>>=1,a*=a,a%=p) if(b&1) res*=a,res%=p;
    return res;
}
ll fpow(ll a,ll b){return fpow(a,b,mod);}

void add(int p){
    for(int i=3*p-2;i<=3*p;i++){
        ha+=mod-fpow(b2,ca[a[i]]);
        ca[a[i]]+=bp[p]; ca[a[i]]%=mod;
        ha+=fpow(b2,ca[a[i]]);
        hb+=mod-fpow(b2,cb[b[i]]);
        cb[b[i]]+=bp[p]; cb[b[i]]%=mod;
        hb+=fpow(b2,cb[b[i]]);
    }
    ha%=mod; hb%=mod;
    return;
}
void del(int p){
    for(int i=3*p-2;i<=3*p;i++){
        ha+=mod-fpow(b2,ca[a[i]]);
        ca[a[i]]+=mod-bp[p]; ca[a[i]]%=mod;
        ha+=fpow(b2,ca[a[i]]);
        hb+=mod-fpow(b2,cb[b[i]]);
        cb[b[i]]+=mod-bp[p]; cb[b[i]]%=mod;
        hb+=fpow(b2,cb[b[i]]);
    }
    ha%=mod; hb%=mod;
    return;    
}

void run(){
    bp[0]=1;
    for(int i=1;i<=n;i++) bp[i]=(bp[i-1]*bas)%mod;

    l=1,r=0;
    for(;l<=n;l++){
        while(r<=n-1){
            if(ha!=hb){
                break;
            }
            add(++r);
        }
        rm[l]=r-(ha!=hb);
        del(l);
    }

    return;
}

#define ONLINE_JUDGE
namespace LightIO
{
    char piBuf[1 << 21];
    int iRead = 0, iEnd = 0;
    char poBuf[1 << 21];
    int poEnd = 0;
    char ptBuf[30];
    int ptEnd = 0;
    const char lendl = '\n';

    inline int getc()
    {
#ifdef ONLINE_JUDGE
        if (iRead == iEnd)
        {
            iRead = 0;
            iEnd = fread(piBuf, 1, 1 << 21, stdin);
            if (!iEnd)
                return EOF;
        }
        return piBuf[iRead++];
#else
        return getchar();
#endif
    }

    inline void flush()
    {
        fwrite(poBuf, 1, poEnd, stdout);
        poEnd = 0;
    }

    inline void putc(char c)
    {
        if (poEnd >> 20)
            flush();
        poBuf[poEnd++] = c;
    }

    class lcin_base
    {
        friend lcin_base operator>>(const lcin_base &fcb, int &x)
        {
            x = 0;
            int f = 0;
            char ch = getc();
            while (ch < '0' || ch > '9')
            {
                if (ch == '-')
                    f = 1;
                ch = getc();
            }
            while (ch >= '0' && ch <= '9')
            {
                x = (x << 1) + (x << 3) + (ch ^ 48);
                ch = getc();
            }
            if (f)
                x = -x;
            return fcb;
        }
        friend lcin_base operator>>(const lcin_base &fcb, char &x)
        {
            x = getc();
            return fcb;
        }
    } lcin;

    class lcout_base
    {
        friend lcout_base operator<<(const lcout_base &fcb, int x)
        {
            ptEnd = 0;
            if (x < 0)
                putc('-'), x = -x;
            if (x == 0)
                putc('0');
            while (x)
            {
                ptBuf[ptEnd++] = (x % 10) ^ 48;
                x /= 10;
            }
            while (--ptEnd >= 0)
                putc(ptBuf[ptEnd]);
            return fcb;
        }
        friend lcout_base operator<<(const lcout_base &fcb, char x)
        {
            putc(x);
            return fcb;
        }
        friend lcout_base operator<<(const lcout_base &fcb, string s)
        {
            for (int i = 0; i < s.length(); i++)
                putc(s[i]);
            return fcb;
        }
    } lcout;
};
using LightIO::lcin;
using LightIO::lcout;
using LightIO::lendl;
using LightIO::flush;

signed main(){
    srand(time(0));

    lcin>>n>>m>>q;
    for(int i=1;i<=3*n;i++) lcin>>a[i];
    for(int j=1;j<=3*n;j++) lcin>>b[j];
    for(int i=1;i<=q;i++){
        lcin>>ql[i]>>qr[i];
    }
    bas=105,b2=19;
    run();
    for(int i=1;i<=q;i++){
        if(qr[i]>rm[ql[i]]) puts("No");
        else puts("Yes");
    }

    return 0;
}

Details


Pretests

Pretest #1:

score: 5
Accepted
time: 0ms
memory: 18084kb

Pretest #2:

score: 5
Accepted
time: 0ms
memory: 18008kb

Pretest #3:

score: 5
Accepted
time: 0ms
memory: 18012kb

Pretest #4:

score: 5
Accepted
time: 2ms
memory: 18008kb

Pretest #5:

score: 5
Accepted
time: 0ms
memory: 18104kb

Pretest #6:

score: 5
Accepted
time: 0ms
memory: 18008kb

Pretest #7:

score: 5
Accepted
time: 2ms
memory: 18012kb

Pretest #8:

score: 5
Accepted
time: 2ms
memory: 18084kb

Pretest #9:

score: 5
Accepted
time: 7ms
memory: 23476kb

Pretest #10:

score: 5
Accepted
time: 4ms
memory: 23072kb

Pretest #11:

score: 5
Accepted
time: 913ms
memory: 33428kb

Pretest #12:

score: 5
Accepted
time: 875ms
memory: 37168kb

Pretest #13:

score: 5
Accepted
time: 8ms
memory: 18044kb

Pretest #14:

score: 5
Accepted
time: 7ms
memory: 18208kb

Pretest #15:

score: 5
Accepted
time: 53ms
memory: 32844kb

Pretest #16:

score: 5
Accepted
time: 51ms
memory: 33112kb

Pretest #17:

score: 5
Accepted
time: 88ms
memory: 20568kb

Pretest #18:

score: 5
Accepted
time: 85ms
memory: 19312kb

Pretest #19:

score: 5
Accepted
time: 908ms
memory: 45444kb

Pretest #20:

score: 5
Accepted
time: 879ms
memory: 52184kb

Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 18036kb

Test #2:

score: 5
Accepted
time: 0ms
memory: 17972kb

Test #3:

score: 5
Accepted
time: 2ms
memory: 18040kb

Test #4:

score: 5
Accepted
time: 3ms
memory: 18092kb

Test #5:

score: 5
Accepted
time: 0ms
memory: 18144kb

Test #6:

score: 5
Accepted
time: 2ms
memory: 18104kb

Test #7:

score: 5
Accepted
time: 3ms
memory: 18020kb

Test #8:

score: 5
Accepted
time: 0ms
memory: 17972kb

Test #9:

score: 5
Accepted
time: 7ms
memory: 21424kb

Test #10:

score: 5
Accepted
time: 8ms
memory: 22992kb

Test #11:

score: 5
Accepted
time: 904ms
memory: 37000kb

Test #12:

score: 5
Accepted
time: 865ms
memory: 35680kb

Test #13:

score: 5
Accepted
time: 8ms
memory: 18120kb

Test #14:

score: 5
Accepted
time: 7ms
memory: 20320kb

Test #15:

score: 5
Accepted
time: 59ms
memory: 32336kb

Test #16:

score: 5
Accepted
time: 50ms
memory: 33100kb

Test #17:

score: 5
Accepted
time: 88ms
memory: 20260kb

Test #18:

score: 5
Accepted
time: 84ms
memory: 20624kb

Test #19:

score: 5
Accepted
time: 911ms
memory: 45564kb

Test #20:

score: 5
Accepted
time: 870ms
memory: 52120kb

Extra Test:

score: 0
Extra Test Passed