結果

問題 No.1673 Lamps on a line
ユーザー Aurora
提出日時 2021-09-12 12:01:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 170,172 KB
実行使用メモリ 9,208 KB
最終ジャッジ日時 2024-06-24 00:14:17
合計ジャッジ時間 4,320 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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