记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 400.0 KiB
#2 Accepted 1ms 376.0 KiB
#3 Accepted 1ms 340.0 KiB
#4 Accepted 1ms 340.0 KiB
#5 Accepted 1ms 380.0 KiB
#6 Accepted 3ms 492.0 KiB
#7 Accepted 3ms 492.0 KiB
#8 Accepted 2ms 488.0 KiB
#9 Accepted 4ms 524.0 KiB
#10 Accepted 7ms 568.0 KiB
#11 Accepted 5ms 760.0 KiB
#12 Accepted 67ms 1.258 MiB
#13 Accepted 43ms 1.23 MiB
#14 Accepted 64ms 1.445 MiB
#15 Accepted 87ms 1.699 MiB
#16 Accepted 1409ms 14.758 MiB
#17 Accepted 2519ms 15.965 MiB
#18 Accepted 1060ms 9.859 MiB
#19 Accepted 1111ms 10.543 MiB
#20 Accepted 3709ms 24.484 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-07-20 11:04:55
评测时间
2021-07-20 11:11:02
评测机
分数
100
总耗时
10110ms
峰值内存
24.484 MiB