记录详情

Wrong Answer


  
正在同步测试数据,请稍后
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Wrong Answer Read 6, expect 36. 2ms 384.0 KiB
#2 Wrong Answer Read 3, expect 7. 1ms 380.0 KiB
#3 Wrong Answer Read 7, expect 250. 1ms 384.0 KiB
#4 Wrong Answer Read 9, expect 70. 1ms 384.0 KiB
#5 Wrong Answer Read 11, expect 164. 2ms 384.0 KiB
#6 Wrong Answer Read 13, expect 534. 4ms 384.0 KiB
#7 Wrong Answer Read 9, expect 106. 4ms 384.0 KiB
#8 Wrong Answer Read 13, expect 1042. 2ms 384.0 KiB
#9 Wrong Answer Read 15, expect 1438. 5ms 384.0 KiB
#10 Wrong Answer Read 15, expect 2639. 6ms 384.0 KiB
#11 Wrong Answer Read 15, expect 2364. 3ms 512.0 KiB
#12 Wrong Answer Read 15, expect 1752. 52ms 1.242 MiB
#13 Wrong Answer Read 20, expect 9697. 39ms 1016.0 KiB
#14 Wrong Answer Read 20, expect 23915. 43ms 1.242 MiB
#15 Wrong Answer Read 16, expect 4016. 58ms 1.496 MiB
#16 Wrong Answer Read 22, expect 108977. 997ms 15.648 MiB
#17 Wrong Answer Read 23, expect 263386. 1047ms 13.926 MiB
#18 Wrong Answer Read 22, expect 166957. 555ms 8.773 MiB
#19 Wrong Answer Read 22, expect 147670. 691ms 9.648 MiB
#20 Wrong Answer Read 23, expect 23685. 2401ms 23.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;
    }
    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++
递交时间
2022-08-21 22:52:14
评测时间
2022-08-21 22:52:14
评测机
分数
0
总耗时
5923ms
峰值内存
23.484 MiB