답안 #142658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142658 2019-08-10T10:00:50 Z Bodo171 가로등 (APIO19_street_lamps) C++14
0 / 100
4594 ms 12096 KB
#include <iostream>
#include <fstream>
#include <set>
using namespace std;
const int nmax=1005;
struct pct
{
    int x,y,val;
}nl;
int n,i,q,j,poz,a,b;
string ini;
bool operator <(pct unu,pct doi)
{
    return unu.x<doi.x;
}
bool operator !=(pct unu,pct doi)
{
    return (unu.x!=doi.x||unu.y!=doi.y||unu.val!=doi.val);
}
set<pct> s;
set<pct>::iterator it;
string tip;
struct aint
{
    pct a[4*nmax];
    int nr;
    void update(int nod,int l,int r,int x,int y,int val)
    {
        ++nr;
        a[nr].x=x,a[nr].y=y,a[nr].val=val;
    }
    int ret;
    void query(int nod,int l,int r,int x,int y)
    {
        for(int idx=1;idx<=nr;idx++)
            if(a[idx].x<=x&&a[idx].y>=y)
                 ret+=a[idx].val;
    }
    int Q(int x,int y)
    {
        ret=0;
        query(1,1,n,x,y);
        return ret;
    }
}A;
void ins(int poz)
{
    pct st=nl,dr=nl,act;
    it=s.lower_bound({poz,0,0});
    if((*it).x==poz+1)
        dr=(*it);
    if(it!=s.begin())
    {
        it--;
        if((*it).y==poz-1)
            st=(*it);
    }
    act.val=i;act.x=act.y=poz;
    if(st!=nl)
    {
        A.update(1,1,n,st.x,st.y,i-st.val);
        act.x=st.x;
        s.erase(st);
    }
    if(dr!=nl)
    {
        A.update(1,1,n,dr.x,dr.y,i-dr.val);
        act.y=dr.y;
        s.erase(dr);
    }
    s.insert(act);
    return;
}
void del(int poz)
{
    pct st=nl,dr=nl,act;
    it=s.lower_bound({poz+1,0,0});
    it--;//mereu se poate
    act=(*it);
    A.update(1,1,n,act.x,act.y,i-act.val);
    s.erase(act);
    if(poz>act.x)
    {
        st={act.x,poz-1,i};
        s.insert(st);
    }
    if(poz<act.y)
    {
        dr={poz+1,act.y,i};
        s.insert(dr);
    }

}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>q;
    cin>>ini;
    ini=" "+ini;
    for(i=1;i<ini.size();i++)
    {
        if(ini[i]=='1')
        {
            j=i;
            while(j<ini.size()&&ini[j]=='1')
                j++;
            j--;
            s.insert({i,j,0});
            i=j;
        }
    }
    for(i=1;i<=q;i++)
    {
        cin>>tip;
        if(tip=="toggle")
        {
            cin>>poz;
            if(ini[poz]=='1')
            {
                ini[poz]='0';
                del(poz);
            }
            else
            {
                ini[poz]='1';
                ins(poz);
            }
        }
        else
        {
            int ans;
            cin>>a>>b;
            it=s.lower_bound({b,0,0});
            if(it!=s.begin())
            {
                it--;
                if((*it).x<=a&&(*it).y>=b-1) ans=i-(*it).val;
                else ans=0;
            }
            ans+=A.Q(a,b-1);
            cout<<ans<<'\n';
        }
    }
    return 0;
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:101:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=1;i<ini.size();i++)
             ~^~~~~~~~~~~
street_lamps.cpp:106:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(j<ini.size()&&ini[j]=='1')
                   ~^~~~~~~~~~~
street_lamps.cpp:132:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
             int ans;
                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1802 ms 1204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Runtime error 37 ms 5984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 12 ms 376 KB Output is correct
5 Correct 4594 ms 12096 KB Output is correct
6 Runtime error 45 ms 11232 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -