Submission #347924

# Submission time Handle Problem Language Result Execution time Memory
347924 2021-01-13T19:11:21 Z denkendoemeer Street Lamps (APIO19_street_lamps) C++14
100 / 100
4094 ms 65092 KB
#include<bits/stdc++.h>
using namespace std;
struct nr
{
    bool ok;
    int st,dr,x,del;
}a[1500005],b[1500005];
int ans[1500005];
int cmp(nr a,nr b)
{
    return a.x<b.x;
}
void update(int st,int dr)
{
    if (dr==st+1)
        return ;
    int mij=(st+dr)/2;
    update(st,mij);
    update(mij,dr);
    int i;
    for(i=st;i<dr;i++)
        b[i].dr=(i<mij);
    inplace_merge(b+st,b+mij,b+dr,cmp);
    int sum=0;
    for(i=st;i<dr;i++){
        if (b[i].ok==0 && b[i].st && b[i].dr)
            sum=sum+b[i].del*b[i].x;
        if (b[i].ok && b[i].st==0 && b[i].dr==0)
            ans[b[i].x]+=sum;
    }
}
int cmp2(nr a,nr b)
{
    return make_pair(-a.dr,a.ok)<make_pair(-b.dr,b.ok);
}
void update2(int st,int dr)
{
    if (dr==st+1)
        return ;
    int mij=(st+dr)/2;
    update2(st,mij);
    update2(mij,dr);
    int i;
    for(i=st;i<dr;i++)
        a[i].st=(i<mij);
    merge(a+st,a+mij,a+mij,a+dr,b+st,cmp2);
    for(i=st;i<dr;i++)
        a[i]=b[i];
    update(st,dr);
}
set<int>st;
int cmp3(nr a,nr b)
{
    return make_pair(a.st,a.ok)<make_pair(b.st,b.ok);
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int n,q,u=0,i;
    char ch;
    scanf("%d%d\n",&n,&q);
    int last=-1;
    st.insert(-1);
    for(i=0;i<n;i++){
        ch=getchar();
        if (ch!='0')
            if (u && a[u-1].dr==i)
                a[u-1].dr=i+1;
            else
                a[u++]=(nr){0,last+1,i+1,-1,-1};
        else
            last=i,st.insert(i);
    }
    scanf("\n");
    st.insert(n);
    string s;
    int num;
    for(i=0;i<q;i++){
        cin>>s;
        if (s=="toggle"){
            int poz;
            scanf("%d\n",&poz);
            poz--;
            auto auxi=st.insert(poz);
            auto it=auxi.first;
            auto it2=auxi.second;
            if (it2)
                num=1;
            else
                num=-1;
            a[u++]=(nr){0,*prev(it)+1,*next(it),i,+num};
            a[u++]=(nr){0,*prev(it)+1,poz,i,-num};
            a[u++]=(nr){0,poz+1,*next(it),i,-num};
            if (num==-1)
                st.erase(it);
            ans[i]=-1;
        }
        else{
            int x,y;
            scanf("%d%d\n",&x,&y);
            x--;
            y--;
            a[u++]={1,x,y,i,0};
            if (*st.lower_bound(x)<y)
                ans[i]=0;
            else
                ans[i]=i;
        }
    }
    sort(a,a+u,cmp3);
    update2(0,u);
    for(i=0;i<q;i++)
        if (ans[i]>=0)
            printf("%d\n",ans[i]);
return 0;
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |     scanf("%d%d\n",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~
street_lamps.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |     scanf("\n");
      |     ~~~~~^~~~~~
street_lamps.cpp:83:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |             scanf("%d\n",&poz);
      |             ~~~~~^~~~~~~~~~~~~
street_lamps.cpp:101:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  101 |             scanf("%d%d\n",&x,&y);
      |             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2794 ms 33980 KB Output is correct
2 Correct 2873 ms 37576 KB Output is correct
3 Correct 2956 ms 38176 KB Output is correct
4 Correct 3343 ms 50228 KB Output is correct
5 Correct 3180 ms 45720 KB Output is correct
6 Correct 3291 ms 53236 KB Output is correct
7 Correct 1675 ms 37956 KB Output is correct
8 Correct 1380 ms 23876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 492 KB Output is correct
2 Correct 6 ms 492 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 3846 ms 63748 KB Output is correct
6 Correct 3497 ms 58348 KB Output is correct
7 Correct 3001 ms 45400 KB Output is correct
8 Correct 1636 ms 23620 KB Output is correct
9 Correct 957 ms 17200 KB Output is correct
10 Correct 1043 ms 18820 KB Output is correct
11 Correct 988 ms 18840 KB Output is correct
12 Correct 1905 ms 37748 KB Output is correct
13 Correct 1636 ms 23876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 5 ms 492 KB Output is correct
3 Correct 6 ms 492 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 2079 ms 29080 KB Output is correct
6 Correct 2679 ms 43992 KB Output is correct
7 Correct 3237 ms 53168 KB Output is correct
8 Correct 4094 ms 65092 KB Output is correct
9 Correct 3319 ms 44704 KB Output is correct
10 Correct 3941 ms 52568 KB Output is correct
11 Correct 3335 ms 44808 KB Output is correct
12 Correct 3936 ms 52728 KB Output is correct
13 Correct 3313 ms 44936 KB Output is correct
14 Correct 3897 ms 52416 KB Output is correct
15 Correct 1911 ms 38192 KB Output is correct
16 Correct 1647 ms 24132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2794 ms 33980 KB Output is correct
9 Correct 2873 ms 37576 KB Output is correct
10 Correct 2956 ms 38176 KB Output is correct
11 Correct 3343 ms 50228 KB Output is correct
12 Correct 3180 ms 45720 KB Output is correct
13 Correct 3291 ms 53236 KB Output is correct
14 Correct 1675 ms 37956 KB Output is correct
15 Correct 1380 ms 23876 KB Output is correct
16 Correct 6 ms 492 KB Output is correct
17 Correct 6 ms 492 KB Output is correct
18 Correct 5 ms 492 KB Output is correct
19 Correct 3 ms 364 KB Output is correct
20 Correct 3846 ms 63748 KB Output is correct
21 Correct 3497 ms 58348 KB Output is correct
22 Correct 3001 ms 45400 KB Output is correct
23 Correct 1636 ms 23620 KB Output is correct
24 Correct 957 ms 17200 KB Output is correct
25 Correct 1043 ms 18820 KB Output is correct
26 Correct 988 ms 18840 KB Output is correct
27 Correct 1905 ms 37748 KB Output is correct
28 Correct 1636 ms 23876 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 7 ms 492 KB Output is correct
33 Correct 2079 ms 29080 KB Output is correct
34 Correct 2679 ms 43992 KB Output is correct
35 Correct 3237 ms 53168 KB Output is correct
36 Correct 4094 ms 65092 KB Output is correct
37 Correct 3319 ms 44704 KB Output is correct
38 Correct 3941 ms 52568 KB Output is correct
39 Correct 3335 ms 44808 KB Output is correct
40 Correct 3936 ms 52728 KB Output is correct
41 Correct 3313 ms 44936 KB Output is correct
42 Correct 3897 ms 52416 KB Output is correct
43 Correct 1911 ms 38192 KB Output is correct
44 Correct 1647 ms 24132 KB Output is correct
45 Correct 1597 ms 24712 KB Output is correct
46 Correct 1762 ms 24968 KB Output is correct
47 Correct 1911 ms 29536 KB Output is correct
48 Correct 3184 ms 50036 KB Output is correct
49 Correct 1199 ms 21316 KB Output is correct
50 Correct 1210 ms 21188 KB Output is correct
51 Correct 1174 ms 21504 KB Output is correct
52 Correct 1052 ms 21700 KB Output is correct
53 Correct 1049 ms 21788 KB Output is correct
54 Correct 1041 ms 21664 KB Output is correct