QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#268781#7748. Karshilov's Matching Problem IIqkm66666RE 0ms0kbC++173.0kb2023-11-28 21:04:082023-11-28 21:04:08

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2023-11-28 21:04:08]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-28 21:04:08]
  • 提交

answer

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<vector>
#include<bitset>
#include<random>
#include<ctime>
#include<queue>
#include<cmath>
#include<list>
#include<map>
#include<set>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long,long long>
#define FF fflush(stdout)
#define inf 0x3f3f3f3f
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//char buf[1<<20],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline int read()
{
    int s=0,f=1;
    char x=getchar();
    while(!isdigit(x))f=(x=='-'?-1:1),x=getchar();
    while(isdigit(x))s=s*10+x-'0',x=getchar();
    return s*f;
}
const int p=1e9+7;
//ll ksm(int a,int b){ll ans=1,bs=a;while(b){if(b&1)ans=ans*bs%p;bs=bs*bs%p;b>>=1;}return ans;}
mt19937 rd(time(0));
#define reaD read
char a[300005];
ll w[150005];
struct hlydl{
    int l,r,id;
    friend bool operator <(hlydl x,hlydl y){
        return x.r<y.r;
    }
}q[150005];
int z[300005];
ll val[150005];
set<int> s;
vector<int> d[150005];
ll ans[150005];
ll c[150005];
int n,m;
void mdf(int x,ll k)
{
    for(int i=x;i<=n;i+=i&-i)
    c[i]+=k;
}
ll qy(int x)
{
    ll s=0;
    for(int i=x;i;i-=i&-i)
    s+=c[i];
    return s;
}
int main()
{
    n=reaD(),m=reaD();
    scanf("%s",a);
    scanf("%s",a+n);
    for(int i=1;i<=n;i++)
    w[i]=reaD(),w[i]+=w[i-1];
    for(int i=1;i<=m;i++)
    {
        int l=read(),r=reaD();
        q[i]=(hlydl){l,r,i};
    }
    sort(q+1,q+m+1);
    z[0]=0;
    for(int i=1,l=0,r=0;i<2*n;i++)
    {
        if(i<=r&&z[i-l]<r-i+1)z[i]=z[i-l];
        else
        {
            z[i]=max(0,r-i+1);
            while(i+z[i]<2*n&&a[z[i]]==a[i+z[i]])z[i]++;
        }
        if(i+z[i]-1>r)l=i,r=i+z[i]-1;
        // cout<<z[i]<<" ";
    }
    for(int i=2*n;i>=1;i--)
    z[i]=z[i-1];
    z[1]=0;
    s.insert(1e9);
    for(int i=1;i<=n;i++)
    s.insert(i);
    ll del=0;
    for(int i=1;i<=n;i++)
    {
        for(auto j:d[i])
        s.erase(j);
        if(*s.begin()<=i)
        val[i]=val[i-*s.begin()+1];
        val[i]+=w[i];
        // cout<<val[i]<<" ";
    }
    // s.clear();
    // s.insert(1e9);
    // for(int i=1;i<=n+n;i++)
    // d[i].clear();
    for(int i=n+1;i<=n+n;i++)
    d[i+z[i]-n].pb(i-n),s.insert(i-n);
    for(int i=1;i<=m;i++)
    {
        int l=q[i].l,r=q[i].r,id=q[i].id;
        for(int o=q[i-1].r+1;o<=r;o++)
        for(auto j:d[o])
        mdf(j,w[z[j+n]]),s.erase(j);//,cout<<j<<" ";
        int x=*s.lower_bound(l);
        if(x<=r)
        {
            ans[id]+=val[r-x+1];//cout<<ans[id];
        }
        // for(int i=1;i<=n;i++)
        // printf("%lld ",qy(i)-qy(i-1));puts("");
        ans[id]+=qy(r)-qy(l-1);
    }
    for(int i=1;i<=m;i++)
    printf("%lld\n",ans[i]);
    system("pause");
    return 0;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

8 5
abbabaab
aababbab
1 2 4 8 16 32 64 128
1 1
2 3
3 5
4 7
1 8

output:


result: