记录详情

Accepted

foo.cc: In function 'int main()':
foo.cc:19:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     int n,m;scanf("%d%d",&n,&m);
      |             ~~~~~^~~~~~~~~~~~~~
foo.cc:27:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     for(int i=1;i<=m;i++) scanf("%d%d",&query[i].l,&query[i].r),query[i].index=i;
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
正在同步测试数据,请稍后
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 3ms 384.0 KiB
#2 Accepted 2ms 384.0 KiB
#3 Accepted 2ms 384.0 KiB
#4 Accepted 2ms 384.0 KiB
#5 Accepted 3ms 384.0 KiB
#6 Accepted 5ms 384.0 KiB
#7 Accepted 15ms 640.0 KiB
#8 Accepted 10ms 384.0 KiB
#9 Accepted 6ms 512.0 KiB
#10 Accepted 17ms 512.0 KiB
#11 Accepted 9ms 768.0 KiB
#12 Accepted 89ms 1.281 MiB
#13 Accepted 46ms 1.25 MiB
#14 Accepted 77ms 1.375 MiB
#15 Accepted 97ms 1.742 MiB
#16 Accepted 1831ms 14.797 MiB
#17 Accepted 2330ms 15.992 MiB
#18 Accepted 1058ms 10.016 MiB
#19 Accepted 1083ms 10.574 MiB
#20 Accepted 3491ms 24.516 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-30 16:07:16
评测时间
2021-12-30 17:01:00
评测机
分数
100
总耗时
10188ms
峰值内存
24.516 MiB