結果

問題 No.1673 Lamps on a line
ユーザー sapphire__15sapphire__15
提出日時 2021-09-10 21:28:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,701 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 121,348 KB
実行使用メモリ 5,548 KB
最終ジャッジ日時 2023-09-02 15:55:39
合計ジャッジ時間 3,861 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 84 ms
4,376 KB
testcase_03 AC 83 ms
4,376 KB
testcase_04 AC 146 ms
4,376 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 126 ms
4,380 KB
testcase_07 AC 110 ms
4,788 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 161 ms
4,376 KB
testcase_10 AC 168 ms
4,376 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 193 ms
5,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define rep(i,n,s) for(int i = (s); i < int(n); i++)
#define MM << " " << 
#define all(x) x.begin(), x.end()

template<class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

template<class T>
bool chmin(T& a, const T b) {
    if(a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template<class T>
bool chmax(T& a, const T b) {
    if(a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template<class T>
void vdeb(std::vector<T> &da) {
    auto n = da.size();
    for(size_t i = 0; i < n; i++) {
        if(i == n-1) std::cout << da[i] << std::endl;
        else std::cout << da[i] << " ";
    }
}
template<>
void vdeb(std::vector<std::string> &da) {
    auto n = da.size();
    for(size_t i = 0; i < n; i++) {
        std::cout << da[i] << std::endl;
    }
}

using namespace std;

int main() {
    int n, q; cin >> n >> q;
    vector<int> da(n);
    vector<int> ans(q);
    rep(i,q,0) {
        int l, r; cin >> l >> r;
        --l;
        if(i) ans[i] = ans[i-1];
        rep(j,r,l) {
            if(da[j]) {
                ans[i]--;
                da[j]--;
            } else {
                ans[i]++;
                da[j]++;
            }
        }
    }
    rep(i,q,0) cout << ans[i] << endl;
}
0