답안 #163964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163964 2019-11-16T12:31:28 Z Leonardo_Paes 가로등 (APIO19_street_lamps) C++17
20 / 100
8 ms 5368 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5+10;

int n, q;

string initial;

vector<int> toggles;

vector<int> events[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    cin >> n >> q;

    initial.resize(n+2);

    for(int i=1; i<=n; i++){
        cin >> initial[i];
        if(initial[i]=='0') events[i].push_back(0);
    }

    toggles.push_back(0);

    if(n<=100 and q<=100){
        for(int t=1; t<=q; t++){
            string op;

            cin >> op;

            if(op[0] == 'q'){
                int a, b;

                cin >> a >> b;

                string now = initial;

                int ans = 0;

                for(int i=0; i<toggles.size(); i++){
                    if(now[toggles[i]]=='0') now[toggles[i]] = '1';
                    else now[toggles[i]] = '0';

                    bool ok = true;

                    for(int j=a; j<b; j++) if(now[j] == '0') ok = false;

                    if(ok) ans++;
                }

                cout << ans << endl;

                toggles.push_back(0);
            }
            else{
                int i;

                cin >> i;

                toggles.push_back(i);
            }
        }
    }
    else{
        for(int t=1; t<=q; t++){
            string op;

            cin >> op;

            if(op[0] == 'q'){
                int a, b;

                cin >> a >> b;

                int ans = 0;

                for(int i=0; i<events[a].size(); i++){
                    if(i%2){
                        ans += events[a][i] - events[a][i-1];
                    }
                    else{
                        continue;
                    }
                }

                if(events[a].size()%2 == 0) ans += t - events[a].back();

                cout << ans << endl;
            }
            else{
                int i;

                cin >> i;

                events[i].push_back(t);
            }
        }
    }

    return 0;
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:44:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i=0; i<toggles.size(); i++){
                              ~^~~~~~~~~~~~~~~
street_lamps.cpp:81:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i=0; i<events[a].size(); i++){
                              ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 5 ms 2680 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 5368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 5240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 5 ms 2680 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Runtime error 8 ms 5368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -