Submission #938899

# Submission time Handle Problem Language Result Execution time Memory
938899 2024-03-05T19:12:39 Z Andreibatman Street Lamps (APIO19_street_lamps) C++14
40 / 100
258 ms 16980 KB
#include <bits/stdc++.h>
using namespace std;
int n,q,i,j,ok,x,y,lazy[1500010];
char sir[300010],op[30];
struct ceva
{
    int mini,cnt;
    ceva operator +(const ceva &x)
    {
        ceva y;
        y.mini=min(x.mini,mini);
        y.cnt=x.cnt+cnt;
        return y;
    }
    bool operator ==(const ceva &x)
    {
        return mini==x.mini && cnt==x.cnt;
    }
}tree[1500010],zero;
void propag(int left,int right,int node)
{
    int mij=(left+right)/2;

    if(tree[2*node].cnt==mij-left+1)
        tree[2*node].mini+=lazy[node];
    if(tree[2*node+1].cnt==right-mij)
        tree[2*node+1].mini+=lazy[node];

    lazy[2*node]+=lazy[node];
    lazy[2*node+1]+=lazy[node];
    lazy[node]=0;
}
void updatelight(int node,int left,int right,int poz,int val)
{
    if(left!=right && lazy[node])
        propag(left,right,node);
    if(left==right)
    {
        if(val==1)
        {
            sir[left]='1';
            tree[node].cnt=1;
        }
        else
        {
            tree[node].cnt=0;
            sir[left]='0';
        }
        return;
    }
    int mij=(left+right)/2;
    if(poz<=mij)
        updatelight(2*node,left,mij,poz,val);
    else
        updatelight(2*node+1,mij+1,right,poz,val);
    int mij2=tree[node].mini;
    tree[node]=tree[2*node]+tree[2*node+1];
}
void updateval()
{
    if(tree[1].cnt==n)
        tree[1].mini++;
    lazy[1]++;
}
ceva query(int node,int left,int right,int st,int dr)
{
    if(left!=right && lazy[node])
        propag(left,right,node);
    if(st<=left && right<=dr)
    {
        //if(tree[node].cnt!=right-left+1 && st!=dr)
        //    return zero;
        return tree[node];
    }
    int mij=(left+right)/2;
    ceva ans1=zero,ans2=zero;
    if(st<=mij && mij>=dr)
        return query(2*node,left,mij,st,dr);
    else if(st>mij && mij<dr)
        return query(2*node+1,mij+1,right,st,dr);
    else if(st<=mij && mij<dr)
    {
        ans1=query(2*node,left,mij,st,dr);
        ans2=query(2*node+1,mij+1,right,st,dr);
        //if(ans1==zero || ans2==zero)
        //    return zero;
        return ans1+ans2;
    }
    return zero;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q>>(sir+1);
    for(i=1;i<=n;i++)
        updatelight(1,1,n,i,sir[i]-'0');
    while(q--)
    {
        updateval();
        cin>>op>>x;
        if(op[0]=='t')
            updatelight(1,1,n,x,1-sir[x]+'0');
        else
        {
            cin>>y;
            cout<<query(1,1,n,x,y-1).mini<<'\n';

        }

    }
    return 0;
}

Compilation message

street_lamps.cpp: In function 'void updatelight(int, int, int, int, int)':
street_lamps.cpp:56:9: warning: unused variable 'mij2' [-Wunused-variable]
   56 |     int mij2=tree[node].mini;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 3240 KB Output is correct
2 Correct 80 ms 3416 KB Output is correct
3 Correct 98 ms 3464 KB Output is correct
4 Correct 159 ms 15700 KB Output is correct
5 Correct 174 ms 15888 KB Output is correct
6 Correct 153 ms 15444 KB Output is correct
7 Correct 157 ms 15448 KB Output is correct
8 Correct 177 ms 16980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 140 ms 14968 KB Output is correct
6 Correct 189 ms 15032 KB Output is correct
7 Correct 221 ms 15188 KB Output is correct
8 Correct 258 ms 16872 KB Output is correct
9 Correct 77 ms 3140 KB Output is correct
10 Correct 87 ms 3152 KB Output is correct
11 Correct 85 ms 3352 KB Output is correct
12 Correct 255 ms 15440 KB Output is correct
13 Correct 256 ms 16872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -