結果

問題 No.1673 Lamps on a line
ユーザー ks2mks2m
提出日時 2021-09-10 21:24:30
言語 Java19
(openjdk 21)
結果
AC  
実行時間 387 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 3,410 ms
コンパイル使用メモリ 71,044 KB
実行使用メモリ 66,480 KB
最終ジャッジ日時 2023-09-02 15:46:55
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,124 KB
testcase_01 AC 44 ms
49,260 KB
testcase_02 AC 226 ms
56,748 KB
testcase_03 AC 230 ms
56,808 KB
testcase_04 AC 306 ms
56,708 KB
testcase_05 AC 138 ms
52,496 KB
testcase_06 AC 283 ms
56,584 KB
testcase_07 AC 278 ms
56,804 KB
testcase_08 AC 79 ms
51,292 KB
testcase_09 AC 356 ms
59,768 KB
testcase_10 AC 387 ms
60,244 KB
testcase_11 AC 155 ms
55,324 KB
testcase_12 AC 385 ms
66,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		int[] a = new int[n];
		int ans = 0;
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int l = Integer.parseInt(sa[0]) - 1;
			int r = Integer.parseInt(sa[1]);
			for (int j = l; j < r; j++) {
				if (a[j] == 0) {
					a[j] = 1;
					ans++;
				} else {
					a[j] = 0;
					ans--;
				}
			}
			pw.println(ans);
		}
		pw.flush();
		br.close();
	}
}
0