记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 2ms 376.0 KiB
#2 Accepted 2ms 424.0 KiB
#3 Accepted 2ms 428.0 KiB
#4 Accepted 1ms 424.0 KiB
#5 Accepted 2ms 360.0 KiB
#6 Accepted 5ms 512.0 KiB
#7 Accepted 5ms 532.0 KiB
#8 Accepted 3ms 484.0 KiB
#9 Accepted 5ms 524.0 KiB
#10 Accepted 9ms 576.0 KiB
#11 Accepted 7ms 744.0 KiB
#12 Accepted 82ms 1.27 MiB
#13 Accepted 53ms 1.238 MiB
#14 Accepted 78ms 1.441 MiB
#15 Accepted 105ms 1.695 MiB
#16 Accepted 1689ms 14.695 MiB
#17 Accepted 3012ms 15.996 MiB
#18 Accepted 1266ms 9.844 MiB
#19 Accepted 1387ms 10.527 MiB
#20 Accepted 4454ms 24.48 MiB

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int maxn=1e6+10,size=2000;
int a[maxn],now[maxn],ans=1,out[maxn];
struct node{
    int l,r;
    int index;
}query[maxn];
int cmp(node x,node y)
{
    if((int)x.l/size == (int)y.l/size) return x.r<y.r;
    return x.l<y.l; 
}
void upd(int x){if(++now[a[x]]==1) ans++;}
void del(int x){if(--now[a[x]]==0) ans--;}
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    string s;cin>>s;
    for(int i=0;i<n;i++) 
    {
        if(s[i]=='+')a[i+1]=a[i]+1;
        if(s[i]=='-')a[i+1]=a[i]-1;
        if(s[i]=='*')a[i+1]=a[i]+3;
    }
    for(int i=1;i<=m;i++) scanf("%d%d",&query[i].l,&query[i].r),query[i].index=i;
    sort(query+1,query+1+m,cmp);
    int nowl=1,nowr=1;now[a[1]]++;
    for(int i=1;i<=m;i++)
    {
        while(query[i].r>nowr) nowr++,upd(nowr);
        while(query[i].r<nowr) del(nowr),nowr--;
        while(query[i].l<nowl) nowl--,upd(nowl);
        while(query[i].l>nowl) del(nowl),nowl++;
        out[query[i].index]=ans;
    }
    for(int i=1;i<=m;i++) printf("%d\n",out[i]);
    return 0;
}

信息

递交者
类型
递交
题目
P1012 F 奇怪的程序(Hard) /[模板]莫队算法
语言
C++
递交时间
2021-12-06 21:01:11
评测时间
2021-12-06 21:01:11
评测机
分数
100
总耗时
12178ms
峰值内存
24.48 MiB