結果
| 問題 | No.2080 Simple Nim Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-25 22:21:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 474 ms / 3,000 ms |
| コード長 | 2,897 bytes |
| 記録 | |
| コンパイル時間 | 4,253 ms |
| コンパイル使用メモリ | 110,812 KB |
| 実行使用メモリ | 51,752 KB |
| 最終ジャッジ日時 | 2024-06-12 07:25:04 |
| 合計ジャッジ時間 | 8,502 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static int[][] NArr(int n) => Enumerable.Repeat(0, n).Select(_ => NList).ToArray();
static void Main()
{
Solve();
}
static void Solve()
{
var c = NList;
var (n, q) = (c[0], c[1]);
var a = NList;
var map = NArr(q);
var ft = new FenwickTree(n + 1);
for (var i = 0; i < n; ++i) if (a[i] == 1) ft.Add(i + 1, 1);
var res = new List<char>();
foreach (var que in map)
{
if (que[0] == 1)
{
if (ft.Sum(que[1]) == ft.Sum(que[1] - 1))
{
if (que[2] == 1) ft.Add(que[1], 1);
}
else
{
if (que[2] > 1) ft.Add(que[1], -1);
}
}
else
{
var sr = ft.Sum(que[2]);
// WriteLine($"1s = {sr - ft.Sum(que[1] - 1)}");
if (sr - ft.Sum(que[1] - 1) == que[2] - que[1] + 1)
{
if ((que[2] - que[1] + 1) % 2 == 1) res.Add('F');
else res.Add('S');
}
else
{
var ok = que[2];
var ng = que[1] - 1;
while (ok - ng > 1)
{
var mid = (ok + ng) / 2;
// WriteLine($"{sr} - {ft.Sum(mid)} == {que[2]} - {mid}");
if (sr - ft.Sum(mid) == que[2] - mid) ok = mid;
else ng = mid;
}
// WriteLine($"1start = {ok}");
if ((que[2] - ok) % 2 == 0) res.Add('F');
else res.Add('S');
}
}
// for (var i = 0; i < n; ++i) Write((ft.Sum(i + 1) - ft.Sum(i)) + " ");
// WriteLine();
}
WriteLine(string.Join("\n", res));
}
class FenwickTree
{
int size;
long[] tree;
public FenwickTree(int size)
{
this.size = size;
tree = new long[size + 2];
}
public void Add(int index, int value)
{
++index;
for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
}
/// <summary>先頭からindexまでの和(include index)</summary>
public long Sum(int index)
{
++index;
var sum = 0L;
for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
return sum;
}
}
}