結果

問題 No.1673 Lamps on a line
ユーザー merlinmerlin
提出日時 2021-09-10 21:26:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 72,088 KB
実行使用メモリ 60,332 KB
最終ジャッジ日時 2023-09-02 15:50:55
合計ジャッジ時間 6,109 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
50,296 KB
testcase_01 AC 65 ms
50,436 KB
testcase_02 AC 246 ms
57,508 KB
testcase_03 AC 247 ms
57,696 KB
testcase_04 AC 319 ms
57,516 KB
testcase_05 AC 134 ms
53,316 KB
testcase_06 AC 296 ms
57,420 KB
testcase_07 AC 277 ms
57,916 KB
testcase_08 AC 88 ms
52,196 KB
testcase_09 AC 347 ms
59,200 KB
testcase_10 AC 343 ms
58,820 KB
testcase_11 AC 170 ms
55,648 KB
testcase_12 AC 339 ms
60,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);
        int ans=0,i;
        boolean t[]=new boolean[n];
        while(q-->0)
        {
            s=bu.readLine().split(" ");
            int l=Integer.parseInt(s[0])-1,r=Integer.parseInt(s[1])-1;
            for(i=l;i<=r;i++)
            {
                t[i]=!t[i];
                if(t[i]) ans++;
                else ans--;
            }
            sb.append(ans+"\n");
        }
        System.out.print(sb);
    }
}
0