답안 #405258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405258 2021-05-16T05:28:27 Z Jarif_Rahman 가로등 (APIO19_street_lamps) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
    int k, n;
    vector<int> mn;
    segtree(int _n){
        n = _n;
        k = 1;
        while(k < n) k*=2;
        k*=2;
        mn.resize(k, 1);
    }
    void toggle(int in){
        in+=k/2;
        mn[in] = !mn[in];
        in/=2;
        while(in > 0){
            mn[in] = min(mn[2*in], mn[2*in+1]);
            in/=2;
        }
    }
    int get(int in){
        return mn[in+k/2];
    }
    int find(int in){
        for(int i = in; i < n; i++) if(get(i) == 0) return i-1;
        return n-1;
    }
    int rfind(int in){
        for(int i = in; i >= 0; i--) if(get(i) == 0) return i+1;
        return 0;
    }
};
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q; cin >> n >> q;
    segtree seg(n);
    for(int i = 0; i < n; i++){
        char x; cin >> x;
        if(x == '0'){
            seg.toggle(i);
        }
    }
    vector<pair<int, int>> ranges;
    vector<int> value;
    vector<bool> bl;
    for(int i = 0; i < n;){
        if(seg.get(i) == 0){
            i++;
            continue;
        }
        int s = i; i = seg.find(i);
        mp[{s, i}] = ranges.size();
        ranges.pb({s, i});
        value.pb(0);
        bl.pb(0);
        i++;
    }
    vector<int> tg;
    vector<tuple<int, int, int>> query;
    for(int i = 0; i < q; i++){
        str tt; cin >> tt;
        if(tt == "toggle"){
            int in; cin >> in; in--;
            tg.pb(in);
        }
        else{
            int a, b; cin >> a >> b; a--, b-=2;
            query.pb({a, b, query.size()});
        }
    }
    map<pair<int, int>, int> mp;
    for(int i = 0; i < tg.size(); i++){
        int in = tg[i];
        
        if(seg.get(in) == 1){
            int l = seg.rfind(in), r = seg.find(in);
            seg.toggle(in);
            value[mp[{l, r}]] = i-value[mp[{l, r}]];
            bl[mp[{l, r}]] = 1;
            mp[{l, r}] = -1;
            if(in-1 >= 0 && seg.get(in-1) == 1){
                l = seg.rfind(in-1);
                mp[{l, in-1}] = ranges.size();
                ranges.pb({l, in-1});
                value.pb(i);
                bl.pb(0);
            }
            if(in+1 < n && seg.get(in+1) == 1){
                r = seg.rfind(in+1);
                mp[{in+1, r}] = ranges.size();
                value.pb(i);
                bl.pb(0);
            }
        }
        else{
            int l, r;
            if(in-1 >= 0 && seg.get(in-1) == 1){
                l = seg.rfind(in-1);
                int ii = mp[{l, in-1}];
                value[ii] = i-value[ii];
                bl[ii] = 1;
                mp[{l, in-1}] = -1;
            }
            if(in+1 < n && seg.get(in+1) == 1){
                r = seg.rfind(in+1);
                int ii = mp[{in+1, r}];
                value[ii] = i-value[ii];
                bl[ii] = 1;
                mp[{in+1, r}] = -1;
            }
            seg.toggle(in);
            l = seg.rfind(in), r = seg.find(in);
            mp[{l, r}] = ranges.size();
            ranges.pb({l, r});
            value.pb(i);
            bl.pb(0);
        }
    }
    for(int i = 0; i < ranges.size(); i++){
        cerr << ranges[i].f << " " << ranges[i].sc << " " << value[i] << " " << bl[i] << " d\n";
    }
    vector<int> ans(query.size());
    for(int qq = 0; qq < query.size(); qq++){
        auto [a, b, in] = query[qq];
        ans[in] = 0;
        for(int i = 0; i < ranges.size(); i++){
            if(!(a >= ranges[i].f && b <= ranges[i].sc)) continue;
            if(bl[i]) ans[in]+=value[i];
            else ans[in]+=in+tg.size()-value[i]+1;
        }
    }
    for(int x: ans) cout << x << "\n";
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:59:9: error: 'mp' was not declared in this scope
   59 |         mp[{s, i}] = ranges.size();
      |         ^~
street_lamps.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 0; i < tg.size(); i++){
      |                    ~~^~~~~~~~~~~
street_lamps.cpp:126:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |     for(int i = 0; i < ranges.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
street_lamps.cpp:130:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     for(int qq = 0; qq < query.size(); qq++){
      |                     ~~~^~~~~~~~~~~~~~
street_lamps.cpp:133:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |         for(int i = 0; i < ranges.size(); i++){
      |                        ~~^~~~~~~~~~~~~~~