結果

問題 No.1673 Lamps on a line
ユーザー moondrinkmoondrink
提出日時 2021-09-23 14:51:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 164,548 KB
実行使用メモリ 5,388 KB
最終ジャッジ日時 2023-09-18 19:53:02
合計ジャッジ時間 3,391 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 13 ms
4,380 KB
testcase_03 AC 13 ms
4,380 KB
testcase_04 AC 22 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 19 ms
4,376 KB
testcase_07 AC 22 ms
5,048 KB
testcase_08 AC 2 ms
4,584 KB
testcase_09 AC 29 ms
4,376 KB
testcase_10 AC 32 ms
4,444 KB
testcase_11 AC 5 ms
4,532 KB
testcase_12 AC 33 ms
5,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

const int N = 1e6;

int n,q;
int a[N];

int main()
{
    scanf("%d %d",&n,&q);
    for(int i = 1;i <= n;i ++ ) a[i] = 0;
    int sum = 0;
    while(q -- )
    {
        int l,r;
        scanf("%d %d",&l,&r);
        for(int i = l;i <= r;i ++ )
        {
            if(a[i] == 0)
            {
                sum ++;
                a[i] ^= 1;
            }
            else
            {
                sum --;
                a[i] ^= 1;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
0