제출 #1367149

#제출 시각아이디문제언어결과실행 시간메모리
1367149po_rag526Street Lamps (APIO19_street_lamps)C++17
20 / 100
5094 ms35796 KiB
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define endl "\n"
#define emb emplace_back
#define io() do{ios::sync_with_stdio(false); cin.tie(nullptr);}while(0)
const ll mod=1e9+7;
const ll infl=1e18;
const int infi=1e9;
const int maxn= 3e5+5;

int main(){
    io();
    int n,q;
    cin >> n >> q;
    string lm;
    cin >> lm;
    map<pair<int,int>,pair<int,int>> m; // pair a,b to pair amount and time
    set<pair<int,int>> cur;
    int pv=0;
    for(int i=0;i<n;i++){
        if(lm[i] == '0') m[{pv,i}] = {0,0},cur.emplace(pv,i),pv=i+1;
    }
    m[{pv,n}] = {0,0};
    cur.emplace(pv,n);
    for(int i=1;i<=q;i++){
        string s;
        cin >> s;
        int a,b;
        if (s == "toggle") {
            cin >> a;
            a--;

            lm[a] = char('1' - lm[a] + '0');

            if (lm[a] == '0') {
                

                auto it = prev(cur.upper_bound({a, infi}));

                auto [l, r] = *it;
                auto [ad, t] = m[{l, r}];

                m[{l, r}] = {ad + i - t, -1};

                m[{l, a}].second = i;
                m[{a + 1, r}].second = i;

                cur.erase(it);
                cur.emplace(l, a);
                cur.emplace(a + 1, r);
            } else {

                auto it1 = cur.lower_bound({a + 1, -1}); 
                auto it2 = prev(it1);                

                auto [l1, r1] = *it2;
                auto [l2, r2] = *it1;

                auto [ad1, t1] = m[{l1, r1}];
                auto [ad2, t2] = m[{l2, r2}];

                m[{l1, r1}] = {ad1 + i - t1, -1};
                m[{l2, r2}] = {ad2 + i - t2, -1};

                m[{l1, r2}].second = i;

                cur.erase(it1);
                cur.erase(it2);
                cur.emplace(l1, r2);
            }
        }
        else{
            cin >> a >> b;
            a--;
            b--;
            int sm = 0;
            for (int j = 0;j <= a; j++) {
                auto it = m.lower_bound({j, b});
                auto ed = m.upper_bound({j, n});

                for (; it != ed; it++) {
                    const auto& [ky, vl] = *it;

                    sm += vl.first;

                    if (vl.second != -1) {
                        sm += i - vl.second;
                    }
                }
            }
            cout << sm << endl;
        }
    }
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…