結果

問題 No.1673 Lamps on a line
ユーザー AuroraAurora
提出日時 2021-09-12 12:01:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 168,636 KB
実行使用メモリ 8,856 KB
最終ジャッジ日時 2023-09-06 05:32:58
合計ジャッジ時間 4,427 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 84 ms
4,376 KB
testcase_03 AC 85 ms
4,380 KB
testcase_04 AC 149 ms
4,376 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 129 ms
4,376 KB
testcase_07 AC 127 ms
7,612 KB
testcase_08 AC 4 ms
6,072 KB
testcase_09 AC 173 ms
4,380 KB
testcase_10 AC 192 ms
5,696 KB
testcase_11 AC 21 ms
5,920 KB
testcase_12 AC 202 ms
8,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

vector<long long int> BIT;
long long int N;

long long int sum(int i){
  long long int s = 0;
  while(i > 0){
    s += BIT[i];
    i -= i & -i;
  }
  return s;
}

void add(int i,long long int x){
  while(i <= N){
    BIT[i] += x;
    i += i & -i;
  }
}

int main(){
  int Q;
  cin >> N >> Q;
  BIT = vector<long long int>(N+1,0);
  vector<int> now(N,0);
  for(int i=0;i<Q;i++){
    int L,R;
    cin >> L >> R;
    for(int j=L;j<=R;j++){
      if(now[j-1] == 0){
        now[j-1] = 1;
        add(j,1);
      }
      else{
        now[j-1] = 0;
        add(j,-1);
      }
    }
    cout << sum(N) << endl;
  }
}
0