結果

問題 No.1673 Lamps on a line
ユーザー 杨娵隅杨娵隅
提出日時 2021-09-10 22:45:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 764 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 199,184 KB
実行使用メモリ 9,336 KB
最終ジャッジ日時 2023-09-02 19:48:46
合計ジャッジ時間 5,962 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,868 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 14 ms
4,368 KB
testcase_03 AC 14 ms
4,368 KB
testcase_04 AC 23 ms
4,372 KB
testcase_05 AC 3 ms
4,368 KB
testcase_06 AC 21 ms
4,372 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
int N, Q;
int a[maxn], tri[maxn];
int lowbit(int x) {return x & -x;}
inline void add(int x, int c)
{
  for (int i = x; i <= N; i += lowbit(i)) tri[i] += c;
}
int sum(int x)
{
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) res += tri[i];
  return res;
}
int query(int l, int r)
{
  return sum(r) - sum(l - 1);
}
int main()
{
  cin >> N >> Q;
  
  for (int i = 1; i <= N; i ++) 
  {
    add(i, a[i]);
  }
  for (int o = 0; o <= Q - 1; o ++)
  {
    int cnt = 0;
    int l, r; scanf("%d %d", &l, &r);
    for (int i = l; i <= r; i ++) add(i, 1);
    for (int i = 1; i <= N; i ++) 
    {
      if (query(i, i) & 1) cnt ++;
    }cout << cnt << "\n";
  }
  
  return 0;
}
0