結果
| 問題 |
No.1091 Range Xor Query
|
| ユーザー |
|
| 提出日時 | 2020-06-24 01:51:27 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 439 ms / 2,000 ms |
| コード長 | 3,439 bytes |
| コンパイル時間 | 969 ms |
| コンパイル使用メモリ | 118,860 KB |
| 実行使用メモリ | 48,360 KB |
| 最終ジャッジ日時 | 2024-07-03 19:41:12 |
| 合計ジャッジ時間 | 12,406 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Contest.D
{
static class Program
{
public static void Solve(Scanner cin)
{
int n = cin.ReadInt();
int q = cin.ReadInt();
var a = cin.ReadIntArray(n);
var st = new Segtree<int>(n, (i, j) => i ^ j, 0);
for (int i = 0; i < n; i++)
{
st.update(i, a[i]);
}
for (int i = 0; i < q; i++)
{
int l = cin.ReadInt() - 1;
int r = cin.ReadInt() - 1;
Console.WriteLine(st.run(l, r + 1));
}
}
public static void Main(string[] args)
{
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
}
class Segtree<T>
{
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex)
{
this.f = f;
this.exnum = ex;
n = 1;
while (n < m) n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++) tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex)
{
for (int i = 0; i < m; ++i) tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x)
{
tree[j + n - 1] = x;
}
public void update(int j, T x)
{
int i = j + n - 1;
tree[i] = x;
while (i > 0)
{
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update()
{
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r)
{
if (r <= s || t <= l) return exnum;
if (s <= l && r <= t) return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
class Scanner
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner()
{
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString()
{
if (i < s.Length) return s[i++];
string st = Console.ReadLine();
while (st == "") st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0) return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N)
{
string[] Array = new string[N];
for (int i = 0; i < N; i++)
{
Array[i] = ReadString();
}
return Array;
}
public int ReadInt()
{
return int.Parse(ReadString());
}
public int[] ReadIntArray(int N, int add = 0)
{
int[] Array = new int[N];
for (int i = 0; i < N; i++)
{
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong()
{
return long.Parse(ReadString());
}
public long[] ReadLongArray(int N, long add = 0)
{
long[] Array = new long[N];
for (int i = 0; i < N; i++)
{
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble()
{
return double.Parse(ReadString());
}
public double[] ReadDoubleArray(int N, double add = 0)
{
double[] Array = new double[N];
for (int i = 0; i < N; i++)
{
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1));
}
}