답안 #979064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979064 2024-05-10T07:25:36 Z Kenjikrab 가로등 (APIO19_street_lamps) C++14
80 / 100
5000 ms 42636 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
typedef array<int,4> arr4;
int const n_max=3e5+15;

set<int> zero;
//char s[n_max];
arr4 arr[3*n_max];
int ans[n_max];
int cnt=0;
int fen[n_max];
inline void upd(int idx,int val)
{
    for(;idx<n_max;idx+=idx&-idx)fen[idx]+=val;
}
inline int qr(int idx)
{
    int ret=0;
    for(;idx;idx-=idx&-idx)ret+=fen[idx];
    return ret;
}
void sol(int l,int r)
{
    if(l>=r)return;
    int mid=(l+r)>>1,p=l;
    sol(l,mid);sol(mid+1,r);
    for(int i=mid+1;i<=r;i++)
    {
        if(arr[i][2])continue;
        while(p<=mid&&arr[p][1]>=arr[i][1]){upd(arr[p][3],arr[p][2]),p++;}
        ans[arr[i][3]]+=qr(arr[i][3]);
    }
    for(int i=l;i<p;i++)
    {
        upd(arr[i][3],-arr[i][2]);
    }
    inplace_merge(arr+l,arr+mid+1,arr+r+1,[&](const arr4 &a,const arr4 &b)
    {return a[1]>b[1];});
}
    string s;
    int n,q;
signed main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    memset(ans,-1,sizeof(ans));
    //scanf("%d%d%s",&n,&q,s+1);
    cin>>n>>q>>s;
    zero.insert(0);
    for(int i=0;i<n;i++)
    { 
        if(!(s[i]-='0'))zero.insert(i+1);
    }
    zero.insert(n+1);
    //char com[10];
    string com;
    int a,b;
    for(int i=1;i<=q;i++)
    {
        //scanf("%s",com);
        cin>>com;
        if(com[0]=='q')
        {
            //scanf("%d%d",&a,&b);
            cin>>a>>b;
            b--;
            arr[cnt++]={a,b,0,i};
            ans[i]=*zero.lower_bound(a)<=b? 0:i;
        }
        else
        {
            //scanf("%d",&a);
            cin>>a;
            if(s[a-1])
            {
                auto it=zero.insert(a).first;
                int l=*prev(it),m=a,r=*next(it);
                arr[cnt++]={l+1,r-1,i,i};
                arr[cnt++]={l+1,m-1,-i,i};
                arr[cnt++]={m+1,r-1,-i,i};
            }
            else
            {
                auto it=zero.find(a);
                int l=*prev(it),m=a,r=*next(it);
                arr[cnt++]={l+1,r-1,-i,i};
                arr[cnt++]={l+1,m-1,i,i};
                arr[cnt++]={m+1,r-1,i,i};
                zero.erase(it);
            }
            s[a-1]^=1;
        }
    }
    sort(arr, arr+cnt, [&](const arr4 &a, const arr4 &b)
    {return a[0]^b[0] ? a[0]<b[0] : ((a[1]!=b[1])? a[1]>b[1]:(b[2]==0)); });
    sol(0,cnt-1);
    for(int i=1;i<=q;i++)
    {
        if(ans[i]==-1)continue;
        else cout<<ans[i]<<"\n";//printf("%d\n",ans[i]);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 21616 KB Output is correct
2 Correct 292 ms 21940 KB Output is correct
3 Correct 254 ms 21552 KB Output is correct
4 Correct 298 ms 28348 KB Output is correct
5 Correct 284 ms 25548 KB Output is correct
6 Correct 303 ms 30492 KB Output is correct
7 Correct 335 ms 27236 KB Output is correct
8 Correct 154 ms 14140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 380 ms 42636 KB Output is correct
6 Correct 340 ms 34876 KB Output is correct
7 Correct 356 ms 27004 KB Output is correct
8 Correct 296 ms 13528 KB Output is correct
9 Correct 219 ms 9392 KB Output is correct
10 Correct 260 ms 11824 KB Output is correct
11 Correct 241 ms 11980 KB Output is correct
12 Correct 494 ms 31996 KB Output is correct
13 Correct 298 ms 17900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4452 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 387 ms 25248 KB Output is correct
6 Correct 375 ms 27224 KB Output is correct
7 Correct 330 ms 35532 KB Output is correct
8 Correct 315 ms 37448 KB Output is correct
9 Correct 243 ms 26776 KB Output is correct
10 Correct 227 ms 29632 KB Output is correct
11 Correct 253 ms 27428 KB Output is correct
12 Correct 224 ms 30776 KB Output is correct
13 Correct 248 ms 27104 KB Output is correct
14 Correct 227 ms 29804 KB Output is correct
15 Correct 529 ms 31808 KB Output is correct
16 Correct 310 ms 16368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 359 ms 21616 KB Output is correct
9 Correct 292 ms 21940 KB Output is correct
10 Correct 254 ms 21552 KB Output is correct
11 Correct 298 ms 28348 KB Output is correct
12 Correct 284 ms 25548 KB Output is correct
13 Correct 303 ms 30492 KB Output is correct
14 Correct 335 ms 27236 KB Output is correct
15 Correct 154 ms 14140 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
20 Correct 380 ms 42636 KB Output is correct
21 Correct 340 ms 34876 KB Output is correct
22 Correct 356 ms 27004 KB Output is correct
23 Correct 296 ms 13528 KB Output is correct
24 Correct 219 ms 9392 KB Output is correct
25 Correct 260 ms 11824 KB Output is correct
26 Correct 241 ms 11980 KB Output is correct
27 Correct 494 ms 31996 KB Output is correct
28 Correct 298 ms 17900 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 2 ms 4452 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
33 Correct 387 ms 25248 KB Output is correct
34 Correct 375 ms 27224 KB Output is correct
35 Correct 330 ms 35532 KB Output is correct
36 Correct 315 ms 37448 KB Output is correct
37 Correct 243 ms 26776 KB Output is correct
38 Correct 227 ms 29632 KB Output is correct
39 Correct 253 ms 27428 KB Output is correct
40 Correct 224 ms 30776 KB Output is correct
41 Correct 248 ms 27104 KB Output is correct
42 Correct 227 ms 29804 KB Output is correct
43 Correct 529 ms 31808 KB Output is correct
44 Correct 310 ms 16368 KB Output is correct
45 Correct 257 ms 18612 KB Output is correct
46 Correct 203 ms 17548 KB Output is correct
47 Correct 215 ms 20368 KB Output is correct
48 Correct 406 ms 31856 KB Output is correct
49 Execution timed out 5062 ms 18700 KB Time limit exceeded
50 Halted 0 ms 0 KB -