답안 #256662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256662 2020-08-03T05:43:10 Z daniel920712 가로등 (APIO19_street_lamps) C++14
20 / 100
420 ms 96632 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
struct A
{
    int l,r;
    int nxl,nxr,nxt;
    int con;
}Node[2000005];
int now=1;
char temp[15];
char all[300005];
int con[105][105]={0};
int Find(int x,int y,int here)
{
    if(here==-1) return 0;
    int t;
    //printf("aa %d\n",Node[here].con);
    if(Node[here].nxt==-2)
    {
        t=Node[here].con;
        if(Node[here].l==y&&Node[here].r==y) return t;
        else if(y<=(Node[here].l+Node[here].r)/2) t+=Find(x,y,Node[here].nxl);
        else t+=Find(x,y,Node[here].nxr);
    }
    else
    {
        t=Node[here].con;
        t+=Find(x,y,Node[here].nxt);
        if(Node[here].l==x&&Node[here].r==x) return t;
        else if(x<=(Node[here].l+Node[here].r)/2) t+=Find(x,y,Node[here].nxl);
        else t+=Find(x,y,Node[here].nxr);
    }
    //printf("%d %d %d %d\n",Node[here].l,Node[here].r,Node[here].nxt,t);
    return t;
}
void build(int l,int r,int con,int here)
{
    Node[here].l=l;
    Node[here].r=r;
    Node[here].nxt=con;
    Node[here].nxl=-1;
    Node[here].nxr=-1;
    Node[here].con=0;
}
void cha(int l1,int r1,int l2,int r2,int con,int here)
{
    int t;
    //printf("%d %d %d %d %d %d\n",l1,r1,l2,r2,here,Node[here].nxt);
    if(Node[here].nxt==-2)
    {
        //return ;
        if(Node[here].l==l2&&Node[here].r==r2)
        {
            Node[here].con+=con;
            return ;
        }
        if(Node[here].nxl==-1)
        {
            Node[here].nxl=now++;
            build(Node[here].l,(Node[here].l+Node[here].r)/2,-2,Node[here].nxl);
        }
        if(Node[here].nxr==-1)
        {
            Node[here].nxr=now++;
            build((Node[here].l+Node[here].r)/2+1,Node[here].r,-2,Node[here].nxr);
        }

        if(r2<=(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxl);
        else if(l2>(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxr);
        else
        {
            cha(l1,r1,l2,(Node[here].l+Node[here].r)/2,con,Node[here].nxl);
            cha(l1,r1,(Node[here].l+Node[here].r)/2+1,r2,con,Node[here].nxr);
        }
    }
    else
    {
        if(Node[here].nxt==-1)
        {
            Node[here].nxt=now++;
            build(0,300000,-2,Node[here].nxt);
        }
        if(Node[here].l==l1&&Node[here].r==r1)
        {
            cha(l1,r1,l2,r2,con,Node[here].nxt);
            return;
        }
        if(Node[here].nxl==-1)
        {
            Node[here].nxl=now++;
            build(Node[here].l,(Node[here].l+Node[here].r)/2,-1,Node[here].nxl);
        }
        if(Node[here].nxr==-1)
        {
            Node[here].nxr=now++;
            build((Node[here].l+Node[here].r)/2+1,Node[here].r,-1,Node[here].nxr);
        }
        if(r1<=(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxl);
        else if(l1>(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxr);
        else
        {
            cha(l1,(Node[here].l+Node[here].r)/2,l2,r2,con,Node[here].nxl);
            cha((Node[here].l+Node[here].r)/2+1,r1,l2,r2,con,Node[here].nxr);
        }
    }
}
int main()
{
    int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok;
    scanf("%d %d",&N,&M);
    scanf("%s",all+1);
    build(0,300000,-1,0);
    l=1;
    r=0;
    for(i=1;i<=N;i++)
    {
        if(all[i]=='1') r=i;
        else
        {
            if(r>=l) cha(l,r+1,l,r+1,M,0);
            l=i+1;
            r=i;
        }
    }
    if(r>=l) cha(l,r+1,l,r+1,M,0);
    for(i=1;i<=M;i++)
    {
        scanf("%s",temp);
        if(temp[0]=='t')
        {
            scanf("%d",&where);
            if(all[where]=='0')
            {
                r1=where;
                l1=where;
                for(j=where-1;j>=1;j--)
                {
                    if(all[j]=='1') l1=j;
                    else break;
                }
                l2=where+1;
                r2=where+1;
                for(j=where+1;j<=N;j++)
                {
                    if(all[j]=='1') r2=j+1;
                    else break;
                }
                cha(l1,r1,l2,r2,M-i,0);
            }
            else
            {
                r1=where;
                l1=where;
                for(j=where-1;j>=1;j--)
                {
                    if(all[j]=='1') l1=j;
                    else break;
                }
                l2=where+1;
                r2=where+1;
                for(j=where+1;j<=N;j++)
                {
                    if(all[j]=='1') r2=j+1;
                    else break;
                }
                cha(l1,r1,l2,r2,i-M,0);
            }
            all[where]=(1-(all[where]-'0'))+'0';
        }
        else
        {
            scanf("%d %d",&l,&r);
            ok=1;
            for(j=l;j<r;j++) if(all[j]=='0') ok=0;
            //printf("aa %d\n",ok);
            printf("%d\n",max(Find(l,r,0)-(M-i)*ok,0));
        }
    }
    return 0;
}

Compilation message

street_lamps.cpp: In function 'void cha(int, int, int, int, int, int)':
street_lamps.cpp:50:9: warning: unused variable 't' [-Wunused-variable]
     int t;
         ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:112:13: warning: unused variable 't' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok;
             ^
street_lamps.cpp:112:35: warning: unused variable 'k' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok;
                                   ^
street_lamps.cpp:113:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
street_lamps.cpp:114:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",all+1);
     ~~~~~^~~~~~~~~~~~
street_lamps.cpp:131:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",temp);
         ~~~~~^~~~~~~~~~~
street_lamps.cpp:134:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&where);
             ~~~~~^~~~~~~~~~~~~
street_lamps.cpp:175:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 1656 KB Output is correct
2 Correct 274 ms 2008 KB Output is correct
3 Correct 420 ms 15480 KB Output is correct
4 Runtime error 98 ms 96632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1664 KB Output is correct
2 Correct 2 ms 1536 KB Output is correct
3 Correct 3 ms 1280 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Execution timed out 100 ms 47608 KB Time limit exceeded (wall clock)
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 2 ms 1280 KB Output is correct
5 Runtime error 99 ms 96632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 253 ms 1656 KB Output is correct
9 Correct 274 ms 2008 KB Output is correct
10 Correct 420 ms 15480 KB Output is correct
11 Runtime error 98 ms 96632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -