제출 #985268

#제출 시각아이디문제언어결과실행 시간메모리
985268nninStreet Lamps (APIO19_street_lamps)C++14
20 / 100
5013 ms524288 KiB
#include<bits/stdc++.h>
using namespace std;

int n, q;
bool status[300005];
vector<pair<int,vector<int>>> mat;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>q;
    string s;
    cin>>s;
    mat.push_back({0, vector<int>(n+1)});
    mat[0].second[0] = 0;
    for(int i=0;i<n;i++) {
        mat[0].second[i+1] = mat[0].second[i];
        if(s[i]-'0'==1) mat[0].second[i+1]++;
        status[i+1] = s[i]-'0';
    }
    for(int i=1;i<=q;i++) {
        cin>>s;
        if(s[0]=='q') {
            int a, b;
            cin>>a>>b;
            int ans = 0;
            for(int j=0;j<mat.size();j++) {
                if(mat[j].second[b-1]-mat[j].second[a-1]!=b-a) continue;
                if(j+1<mat.size()) ans += mat[j+1].first-mat[j].first;
                else ans += i-mat[j].first;
            }
            cout<<ans<<'\n';
        } else {
            int a;
            cin>>a;
            int idx = mat.size();
            mat.push_back({i, mat[idx-1].second});
            for(int j=a;j<=n;j++) mat[idx].second[j] += (status[a] ? -1:1);
            status[a] = !status[a];
        }
    }
}

/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/

컴파일 시 표준 에러 (stderr) 메시지

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:26:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             for(int j=0;j<mat.size();j++) {
      |                         ~^~~~~~~~~~~
street_lamps.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                 if(j+1<mat.size()) ans += mat[j+1].first-mat[j].first;
      |                    ~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...