buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Linq; class C { static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray(); static void Main() { var h = Read(); int n = h[0], m = h[1]; var scs = new int [m].Select(_ => Read()).ToArray(); var r = Enumerable.Range(0, 1000) .Select(i => i.ToString()) .First(s => s.Length == n && scs.All(sc => s[sc[0] - 1] - '0' == sc[1])); Console.WriteLine(r ?? "-1"); } }
using System; using System.Linq; class C { static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray(); static void Main() { var h = Read(); int n = h[0], m = h[1]; var scs = new int [m].Select(_ => Read()).ToArray(); var r = Enumerable.Range(0, 1000) .Select(i => i.ToString()) .FirstOrDefault(s => s.Length == n && scs.All(sc => s[sc[0] - 1] - '0' == sc[1])); Console.WriteLine(r ?? "-1"); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
163
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc157_c { class Program { static void Main(string[] args) { var N = CIn.ReadInt(); var M = CIn.ReadInt(); var s = new int[M]; var c = new int[M]; for (var i = 0; i < M; i++) { s[i] = CIn.ReadInt(); c[i] = CIn.ReadInt(); } for (var ans = Math.Pow(10, N - 1); ans < Math.Pow(10, N); ans++) { var S = ans.ToString(); var flag = true; for (var i = 0; i < M; i++) { if (S[s[i] - 1] != c[i] + '0') { flag = false; break; } } if (flag == true) { Console.WriteLine(ans); return; } } Console.WriteLine("-1"); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc157_c { class Program { static void Main(string[] args) { var N = CIn.ReadInt(); var M = CIn.ReadInt(); var s = new int[M]; var c = new int[M]; for (var i = 0; i < M; i++) { s[i] = CIn.ReadInt(); c[i] = CIn.ReadInt(); } for (var ans = N == 1 ? 0 : Math.Pow(10, N - 1); ans < Math.Pow(10, N); ans++) { var S = ans.ToString(); var flag = true; for (var i = 0; i < M; i++) { if (S[s[i] - 1] != c[i] + '0') { flag = false; break; } } if (flag == true) { Console.WriteLine(ans); return; } } Console.WriteLine("-1"); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 10, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
8
551
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var keta = int.Parse(nm[0]); var time = int.Parse(nm[1]); var info = new string[time][]; var result = "-1"; var flag = true; for (int i = 0; i < time; i++) { info[i] = Console.ReadLine().Split(' '); } var num = new char[keta]; for (int i = 0; i < keta; i++) { num[i] = 'e'; } for (int i = 0; i < time; i++) { if (num[int.Parse(info[i][0]) - 1] == 'e') { var tmp = info[i][1].ToCharArray(); num[int.Parse(info[i][0]) - 1] = tmp[0]; } else { var tmp = info[i][1].ToCharArray(); if (num[int.Parse(info[i][0]) - 1] != tmp[0]) { flag = false; break; } } if (num[0] == '0') { flag = false; break; } } if (num[0] == 'e') { num[0] = '1'; } if (keta == 1 && num[0] == '0' || keta == 1 && num[0] == '1') { flag = true; num[0] = '0'; } for (int i = 1; i < keta; i++) { if (num[i] == 'e') { num[i] = '0'; } } if (flag == true) { result = new string(num); } Console.WriteLine(result); // Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var keta = int.Parse(nm[0]); var time = int.Parse(nm[1]); var info = new string[time][]; var result = "-1"; var flag = true; for (int i = 0; i < time; i++) { info[i] = Console.ReadLine().Split(' '); } var num = new char[keta]; for (int i = 0; i < keta; i++) { num[i] = 'e'; } for (int i = 0; i < time; i++) { if (num[int.Parse(info[i][0]) - 1] == 'e') { var tmp = info[i][1].ToCharArray(); num[int.Parse(info[i][0]) - 1] = tmp[0]; } else { var tmp = info[i][1].ToCharArray(); if (num[int.Parse(info[i][0]) - 1] != tmp[0]) { flag = false; break; } } if (num[0] == '0') { flag = false; break; } } if (keta != 1 && num[0] == 'e') { num[0] = '1'; } if (keta == 1 && num[0] == '0' || keta == 1 && num[0] == 'e') { flag = true; num[0] = '0'; } for (int i = 1; i < keta; i++) { if (num[i] == 'e') { num[i] = '0'; } } if (flag == true) { result = new string(num); } Console.WriteLine(result); // Console.ReadKey(); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 15, 16, 12, 16, 12, 16, 12, 252, 0, 253], ["+", 15, 16, 12, 16, 12, 16, 12, 252, 0, 253]]
8
456
6
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var dict = new Dictionary<int, int>(); for (int i = 0; i < nm[1]; i++) { var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); if (!dict.ContainsKey(vals[0])) { dict.Add(vals[0], vals[1]); } else { if (dict[vals[0]] != vals[1]) { Console.WriteLine(-1); return; } } if (dict.ContainsKey(1) && dict[1] == 0 && dict[0] > 1) { Console.WriteLine(-1); return; } } var result = new int[nm[0]]; for (int i = 0; i < nm[0]; i++) { if (dict.ContainsKey(i + 1)) { result[i] = dict[i + 1]; } else { result[i] = 0; } } if (result[0] == 0 && nm[0] > 1) { result[0]++; } Console.WriteLine(string.Join("", result)); } }
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var dict = new Dictionary<int, int>(); for (int i = 0; i < nm[1]; i++) { var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); if (!dict.ContainsKey(vals[0])) { dict.Add(vals[0], vals[1]); } else { if (dict[vals[0]] != vals[1]) { Console.WriteLine(-1); return; } } if (dict.ContainsKey(1) && dict[1] == 0 && nm[0] > 1) { Console.WriteLine(-1); return; } } var result = new int[nm[0]]; for (int i = 0; i < nm[0]; i++) { if (dict.ContainsKey(i + 1)) { result[i] = dict[i + 1]; } else { result[i] = 0; } } if (result[0] == 0 && nm[0] > 1) { result[0]++; } Console.WriteLine(string.Join("", result)); } }
[["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22]]
8
328
2
using System; using System.Collections.Generic; namespace CsAtCoderSubmitExam { class BeginnerContest157 { // C - Guess The Number class SC { public int S; public int C; public SC(int s, int c) { S = s; C = c; } public override string ToString() { return $"S:{S}, C:{C}"; } } static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var N = int.Parse(nm[0]); var M = int.Parse(nm[1]); var SCs = new List<SC>(); for (var i = 0; i < M; i++) { var sc = Console.ReadLine().Split(' '); SCs.Add(new SC(int.Parse(sc[0]), int.Parse(sc[1]))); } var min = (int)Math.Pow(10, N - 1); min = (min == 1) ? 0 : min; var max = (int)Math.Pow(10, N) - 1; var ans = -1; for (var i = min; i < max; i++) { var aok = true; foreach (var sc in SCs) { var colS = GetColS(i, sc.S, N); if (colS != sc.C) { aok = false; break; } } if (aok) { ans = i; break; } } Console.WriteLine(ans); } private static int GetColS(int value, int s, int N) { var ret = -1; var i = 0; for (var p = (int)Math.Pow(10, N - 1); 1 <= p; p = p / 10) { i++; if (i == s) { ret = (value / p) % 10; break; } } return ret; } } }
using System; using System.Collections.Generic; namespace CsAtCoderSubmitExam { class BeginnerContest157 { // C - Guess The Number class SC { public int S; public int C; public SC(int s, int c) { S = s; C = c; } public override string ToString() { return $"S:{S}, C:{C}"; } } static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var N = int.Parse(nm[0]); var M = int.Parse(nm[1]); var SCs = new List<SC>(); for (var i = 0; i < M; i++) { var sc = Console.ReadLine().Split(' '); SCs.Add(new SC(int.Parse(sc[0]), int.Parse(sc[1]))); } var min = (int)Math.Pow(10, N - 1); min = (min == 1) ? 0 : min; var max = (int)Math.Pow(10, N) - 1; var ans = -1; for (var i = min; i <= max; i++) { var aok = true; foreach (var sc in SCs) { var colS = GetColS(i, sc.S, N); if (colS != sc.C) { aok = false; break; } } if (aok) { ans = i; break; } } Console.WriteLine(ans); } private static int GetColS(int value, int s, int N) { var ret = -1; var i = 0; for (var p = (int)Math.Pow(10, N - 1); 1 <= p; p = p / 10) { i++; if (i == s) { ret = (value / p) % 10; break; } } return ret; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
410
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var nm = ReadIntArray(); IList<int[]> pairs = new List<int[]>(); for (int i = 0; i < nm[1]; i++) { var r = ReadIntArray(); pairs.Add(new int[] { r[0], r[1] }); } for (int i = 1; i < 1000; i++) { if (i.ToString().Length < nm[0]) { continue; } if (pairs.All(item => i.ToString()[item[0] - 1].ToString() == item[1].ToString())) { Console.WriteLine(i.ToString()); return; } } Console.WriteLine(-1); } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var nm = ReadIntArray(); IList<int[]> pairs = new List<int[]>(); for (int i = 0; i < nm[1]; i++) { var r = ReadIntArray(); pairs.Add(new int[] { r[0], r[1] }); } for (int i = 0; i < 1000; i++) { if (i.ToString().Length < nm[0]) { continue; } if (pairs.All(item => i.ToString()[item[0] - 1].ToString() == item[1].ToString())) { Console.WriteLine(i.ToString()); return; } } Console.WriteLine(-1); } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
393
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n, m; sc.Multi(out n, out m); var s = new char[n]; for (int i = 0; i < m; i++) { int j; char c; sc.Multi(out j, out c); --j; if (s[j] != 0 && s[j] != c || j == 0 && c == '0') { Prt(-1); return; } s[j] = c; } for (int i = 0; i < n; i++) { if (s[i] == 0) { s[i] = i == 0 && n > 1 ? '1' : '0'; } } Prt(new string(s)); } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static readonly int M = 1000000007; // public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(params bool[] conds) { foreach (var cond in conds) if (!cond) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b) { a = v[0]; b = v[1]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) { a = v[0]; b = v[1]; c = v[2]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4]; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n, m; sc.Multi(out n, out m); var s = new char[n]; for (int i = 0; i < m; i++) { int j; char c; sc.Multi(out j, out c); --j; if (s[j] != 0 && s[j] != c || j == 0 && n > 1 && c == '0') { Prt(-1); return; } s[j] = c; } for (int i = 0; i < n; i++) { if (s[i] == 0) { s[i] = i == 0 && n > 1 ? '1' : '0'; } } Prt(new string(s)); } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static readonly int M = 1000000007; // public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(params bool[] conds) { foreach (var cond in conds) if (!cond) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b) { a = v[0]; b = v[1]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) { a = v[0]; b = v[1]; c = v[2]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4]; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } }
[["+", 15, 16, 12, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 16, 12, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98]]
8
2,326
4
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public class Condition { public int S { get; set; } public int C { get; set; } } public void Solve() { var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var N = items[0]; var M = items[1]; var table = new List<Condition>(); foreach (var i in Enumerable.Range(0, M)) { var items2 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var s = items2[0]; var c = items2[1]; table.Add(new Condition { S = s, C = c }); } var answer = -1; int min; int max; switch (N) { case 1: min = 0; max = 9; break; case 2: min = 10; max = 99; break; case 3: min = 100; max = 999; break; default: throw new Exception("エラー"); } foreach (var num in Enumerable.Range(min, max - min + 1)) { var checkText = num.ToString("000"); if (table.Any(pair => checkText[pair.S - 1].ToString() != pair.C.ToString())) { continue; } else { answer = num; break; } } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public class Condition { public int S { get; set; } public int C { get; set; } } public void Solve() { var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var N = items[0]; var M = items[1]; var table = new List<Condition>(); foreach (var i in Enumerable.Range(0, M)) { var items2 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var s = items2[0]; var c = items2[1]; table.Add(new Condition { S = s, C = c }); } var answer = -1; int min; int max; switch (N) { case 1: min = 0; max = 9; break; case 2: min = 10; max = 99; break; case 3: min = 100; max = 999; break; default: throw new Exception("エラー"); } foreach (var num in Enumerable.Range(min, max - min + 1)) { var checkText = num.ToString($"D{N}"); if (table.Any(pair => checkText[pair.S - 1].ToString() != pair.C.ToString())) { continue; } else { answer = num; break; } } Console.WriteLine(answer); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46]]
8
427
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main() { var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = nm[0]; var m = nm[1]; var sc = new int [m][]; for (int i = 0; i < m; i++) { sc[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } if (sc.Any(x => sc.Any(y => y[0] == x[0] && y[1] != x[1]))) { Console.WriteLine("-1"); return; } var ansString = new string[n]; for (int i = 0; i < n; i++) { var digits = sc.Where(x => x[0] == i + 1); if (digits.Any()) { ansString[i] = digits.Min(x => x[1]).ToString(); } else { ansString[i] = i == 0 ? "1" : "0"; } } var ans = int.Parse(string.Join("", ansString)); if (ans.ToString().Length == n) { Console.WriteLine(ans); } else { Console.WriteLine("-1"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main() { var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = nm[0]; var m = nm[1]; var sc = new int [m][]; for (int i = 0; i < m; i++) { sc[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } if (sc.Any(x => sc.Any(y => y[0] == x[0] && y[1] != x[1]))) { Console.WriteLine("-1"); return; } var ansString = new string[n]; for (int i = 0; i < n; i++) { var digits = sc.Where(x => x[0] == i + 1); if (digits.Any()) { ansString[i] = digits.Min(x => x[1]).ToString(); } else { ansString[i] = i == 0 && n > 1 ? "1" : "0"; } } var ans = int.Parse(string.Join("", ansString)); if (ans.ToString().Length == n) { Console.WriteLine(ans); } else { Console.WriteLine("-1"); } } }
[["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 98], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 31, 22], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 17, 47], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 12, 203]]
8
325
4
using System; namespace AtC157 { class Program { static void Main(string[] args) { string[] NM = Console.ReadLine().Split(' '); int N = int.Parse(NM[0]); int M = int.Parse(NM[1]); int[] s = new int[M]; int[] c = new int[M]; bool[] a = new bool[N + 1]; int[] b = new int[N + 1]; bool error = false; for (int i = 0; i < M; i++) { string[] sc = Console.ReadLine().Split(' '); s[i] = int.Parse(sc[0]); c[i] = int.Parse(sc[1]); if (a[s[i]]) { if (b[s[i]] != c[i]) error = true; } else { a[s[i]] = true; b[s[i]] = c[i]; } if (N > 1 && s[i] == 1 && c[i] == 0) error = true; } if (error) { Console.WriteLine(-1); return; } int ans = 0; if (b[1] == 0) b[1] = 1; for (int i = 1; i <= N; i++) { ans = ans * 10 + b[i]; } Console.WriteLine(ans); } } }
using System; namespace AtC157 { class Program { static void Main(string[] args) { string[] NM = Console.ReadLine().Split(' '); int N = int.Parse(NM[0]); int M = int.Parse(NM[1]); int[] s = new int[M]; int[] c = new int[M]; bool[] a = new bool[N + 1]; int[] b = new int[N + 1]; bool error = false; for (int i = 0; i < M; i++) { string[] sc = Console.ReadLine().Split(' '); s[i] = int.Parse(sc[0]); c[i] = int.Parse(sc[1]); if (a[s[i]]) { if (b[s[i]] != c[i]) error = true; } else { a[s[i]] = true; b[s[i]] = c[i]; } if (N > 1 && s[i] == 1 && c[i] == 0) error = true; } if (error) { Console.WriteLine(-1); return; } int ans = 0; if (b[1] == 0 && N > 1) b[1] = 1; for (int i = 1; i <= N; i++) { ans = ans * 10 + b[i]; } Console.WriteLine(ans); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
335
4
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } // static long mod = 1000000007; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var m = int.Parse(spl[1]); StringBuilder str = new StringBuilder(); for (int i = 0; i < n; i++) { str.Append("X"); } // Dictionary<int, int> hash = new Dictionary<int, int>(); for (int i = 0; i < m; i++) { spl = input.ReadLine().Split(' '); var s = int.Parse(spl[0]); var c = int.Parse(spl[1]); var ch = (char)('0' + c); if (s == 1 && c == 0) return -1; if (str[s - 1] != 'X' && str[s - 1] != ch) return -1; str[s - 1] = ch; } if (str[0] == 'X' && n != 1) str[0] = '1'; var v = int.Parse(str.Replace('X', '0').ToString()); return v; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } // static long mod = 1000000007; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var m = int.Parse(spl[1]); StringBuilder str = new StringBuilder(); for (int i = 0; i < n; i++) { str.Append("X"); } // Dictionary<int, int> hash = new Dictionary<int, int>(); for (int i = 0; i < m; i++) { spl = input.ReadLine().Split(' '); var s = int.Parse(spl[0]); var c = int.Parse(spl[1]); var ch = (char)('0' + c); if (n != 1 && s == 1 && c == 0) return -1; if (str[s - 1] != 'X' && str[s - 1] != ch) return -1; str[s - 1] = ch; } if (str[0] == 'X' && n != 1) str[0] = '1'; var v = int.Parse(str.Replace('X', '0').ToString()); return v; } }
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
8
346
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; var c = Enumerable.Repeat(0, nm[1]) .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); for (int i = 1; i < 1000; i++) { var s = i.ToString(); if (s.Length != n) continue; if (!c.All(x => s[x[0] - 1] - '0' == x[1])) continue; Console.WriteLine(i); return; } Console.WriteLine(-1); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; var c = Enumerable.Repeat(0, nm[1]) .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); for (int i = 0; i < 1000; i++) { var s = i.ToString(); if (s.Length != n) continue; if (!c.All(x => s[x[0] - 1] - '0' == x[1])) continue; Console.WriteLine(i); return; } Console.WriteLine(-1); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
256
2
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static Output; using static Utils; public class CP { Input sc; public void Solve() { sc = new Input(); var t = 1; // var sw = new Stopwatch(); // sw.Start(); while (t-- > 0) { case1(); } // sw.Stop(); // Put(sw.ElapsedMilliseconds + "ms"); } public void case1() { var n = sc.cin<int>(); var s = sc.cin<string>(); var q = sc.cin<int>(); var seg = new SegmentTree<long>(n, 0, (a, b) => a | b); for (int i = 0; i < n; ++i) { seg.Update(i, 1 << (s[i] - 'a')); } while (q-- > 0) { var oo = sc.cin<int>(); if (oo == 1) { var ni = sc.cin<int>(); var c = sc.cin<char>(); seg.Update(ni, 1 << (c - 'a')); } else { var l = sc.cin<int>() - 1; var r = sc.cin<int>(); var ans = seg.Query(l, r); Put(popcnt(ans)); } } } } public class SegmentTree<T> { int N; T[] seg; T E; Func<T, T, T> F; public SegmentTree(T[] arr, T e, Func<T, T, T> f) { E = e; F = f; N = 1; while (arr.Length > N) N <<= 1; seg = new T[2 * N - 1]; seg = Enumerable.Repeat(E, seg.Length).ToArray(); for (int i = 0; i < arr.Length; ++i) { seg[i + N - 1] = arr[i]; } for (int i = N - 2; i >= 0; --i) { seg[i] = F(seg[2 * i + 1], seg[2 * i + 2]); } } public SegmentTree(int n, T e, Func<T, T, T> f) : this(Enumerable.Repeat(e, n).ToArray(), e, f) {} public void Update(int k, T a) { k += N - 1; seg[k] = a; while (k > 0) { k = (k - 1) / 2; seg[k] = F(seg[k * 2 + 1], seg[k * 2 + 2]); } } public T Query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (r <= a || b <= l) return E; if (a <= l && r <= b) return seg[k]; int m = (l + r) / 2; return F(Query(a, b, k * 2 + 1, l, m), Query(a, b, k * 2 + 2, m, r)); } } public class BinarySearch { public static int Lower_Bound<T>(IList<T> Array, T Target) { return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Lower_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; // always ng var r = Array.Count(); // always ok while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res >= 0) r = mid; else l = mid; } return r; } public static int Upper_Bound<T>(IList<T> Array, T Target) { return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Upper_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; var r = Array.Count; while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res > 0) r = mid; else l = mid; } return r; } public static bool Contains<T>(IList<T> Arr, T Target) { return Contains<T>(Arr, Target, Comparer<T>.Default.Compare); } public static bool Contains<T>(IList<T> Arr, T Target, Comparison<T> Comp) { return (Upper_Bound(Arr, Target, Comp) - Lower_Bound(Arr, Target, Comp) > 0); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const long MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { if (a == 0) return b; while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static int popcnt(long a) { int cnt = 0; while (a > 0) { if ((a & 1) == 1) ++cnt; a >>= 1; } return cnt; } public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) { int n = lis.Count; int i = n - 1; while (i - 1 >= 0) { if (cmp(lis[i - 1], lis[i]) < 0) break; --i; } if (i == 0) return false; int j = i; while (j + 1 < n) { if (cmp(lis[i - 1], lis[j + 1]) > 0) break; ++j; } var _q = lis[j]; lis[j] = lis[i - 1]; lis[i - 1] = _q; int k = i; int l = n - 1; while (k < l) { var _p = lis[k]; lis[k] = lis[l]; lis[l] = _p; ++k; --l; } return true; } public static bool NextPermutation<T>(IList<T> lis) => NextPermutation(lis, Comparer<T>.Default.Compare); } public class PriorityQueue<T> { List<T> _item; public int Count { get { return _item.Count; } } bool _isascend { get; set; } public T Peek { get { return _item[0]; } } Comparison<T> Comp; public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null) : this(Comparer<T>.Default.Compare, IsAscend, list) {} public PriorityQueue(Comparison<T> cmp, bool IsAscend = true, IEnumerable<T> list = null) { _item = new List<T>(); _isascend = IsAscend; this.Comp = cmp; if (list != null) { _item.AddRange(list); Build(); } } private int Compare(int i, int j) => (_isascend ? -1 : 1) * Comp(_item[i], _item[j]); private void Swap(int i, int j) { var t = _item[i]; _item[i] = _item[j]; _item[j] = t; } private int Parent(int i) => (i - 1) >> 1; private int Left(int i) => (i << 1) + 1; public T Enqueue(T val) { int i = _item.Count; _item.Add(val); while (i > 0) { int p = Parent(i); if (Compare(i, p) > 0) Swap(i, p); i = p; } return val; } private void Heapify(int index) { for (int i = index, j; (j = Left(i)) < _item.Count; i = j) { if (j != _item.Count - 1 && Compare(j, j + 1) < 0) j++; if (Compare(i, j) < 0) Swap(i, j); } } public T Dequeue() { T val = _item[0]; _item[0] = _item[_item.Count - 1]; _item.RemoveAt(_item.Count - 1); Heapify(0); return val; } private void Build() { for (var i = (_item.Count >> 1) - 1; i >= 0; i--) Heapify(i); } public bool Any() => Count > 0; } class Program { static void Main(string[] args) { var CP = new CP(); CP.Solve(); } } public static class Output { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } } public class Input { public static string Str => Console.ReadLine(); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; if (IsTypeEqual<T, char>()) { var list = new List<T>(); foreach (var t in s) { foreach (var u in t) { list.Add(ConvertType<T, char>(char.Parse(u.ToString()))); } } return list.ToArray(); } foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } Queue<string> q = new Queue<string>(); void next() { var ss = Str.Split(' '); foreach (var item in ss) q.Enqueue(item); } public T cin<T>() { if (!q.Any()) next(); return Cast<T>(q.Dequeue()); } public void mul<T>(out T t) { t = cin<T>(); } public void mul<T, U>(out T t, out U u) { t = cin<T>(); u = cin<U>(); } public void mul<T, U, V>(out T t, out U u, out V v) { t = cin<T>(); u = cin<U>(); v = cin<V>(); } public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); } public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); } public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x, out Y y) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); } public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w, out X x, out Y y, out Z z) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); z = cin<Z>(); } public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static Output; using static Utils; public class CP { Input sc; public void Solve() { sc = new Input(); var t = 1; // var sw = new Stopwatch(); // sw.Start(); while (t-- > 0) { case1(); } // sw.Stop(); // Put(sw.ElapsedMilliseconds + "ms"); } public void case1() { var n = sc.cin<int>(); var s = sc.cin<string>(); var q = sc.cin<int>(); var seg = new SegmentTree<long>(n, 0, (a, b) => a | b); for (int i = 0; i < n; ++i) { seg.Update(i, 1 << (s[i] - 'a')); } while (q-- > 0) { var oo = sc.cin<int>(); if (oo == 1) { var ni = sc.cin<int>() - 1; var c = sc.cin<char>(); seg.Update(ni, 1 << (c - 'a')); } else { var l = sc.cin<int>() - 1; var r = sc.cin<int>(); var ans = seg.Query(l, r); Put(popcnt(ans)); } } } } public class SegmentTree<T> { int N; T[] seg; T E; Func<T, T, T> F; public SegmentTree(T[] arr, T e, Func<T, T, T> f) { E = e; F = f; N = 1; while (arr.Length > N) N <<= 1; seg = new T[2 * N - 1]; seg = Enumerable.Repeat(E, seg.Length).ToArray(); for (int i = 0; i < arr.Length; ++i) { seg[i + N - 1] = arr[i]; } for (int i = N - 2; i >= 0; --i) { seg[i] = F(seg[2 * i + 1], seg[2 * i + 2]); } } public SegmentTree(int n, T e, Func<T, T, T> f) : this(Enumerable.Repeat(e, n).ToArray(), e, f) {} public void Update(int k, T a) { k += N - 1; seg[k] = a; while (k > 0) { k = (k - 1) / 2; seg[k] = F(seg[k * 2 + 1], seg[k * 2 + 2]); } } public T Query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (r <= a || b <= l) return E; if (a <= l && r <= b) return seg[k]; int m = (l + r) / 2; return F(Query(a, b, k * 2 + 1, l, m), Query(a, b, k * 2 + 2, m, r)); } } public class BinarySearch { public static int Lower_Bound<T>(IList<T> Array, T Target) { return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Lower_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; // always ng var r = Array.Count(); // always ok while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res >= 0) r = mid; else l = mid; } return r; } public static int Upper_Bound<T>(IList<T> Array, T Target) { return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Upper_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; var r = Array.Count; while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res > 0) r = mid; else l = mid; } return r; } public static bool Contains<T>(IList<T> Arr, T Target) { return Contains<T>(Arr, Target, Comparer<T>.Default.Compare); } public static bool Contains<T>(IList<T> Arr, T Target, Comparison<T> Comp) { return (Upper_Bound(Arr, Target, Comp) - Lower_Bound(Arr, Target, Comp) > 0); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const long MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { if (a == 0) return b; while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static int popcnt(long a) { int cnt = 0; while (a > 0) { if ((a & 1) == 1) ++cnt; a >>= 1; } return cnt; } public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) { int n = lis.Count; int i = n - 1; while (i - 1 >= 0) { if (cmp(lis[i - 1], lis[i]) < 0) break; --i; } if (i == 0) return false; int j = i; while (j + 1 < n) { if (cmp(lis[i - 1], lis[j + 1]) > 0) break; ++j; } var _q = lis[j]; lis[j] = lis[i - 1]; lis[i - 1] = _q; int k = i; int l = n - 1; while (k < l) { var _p = lis[k]; lis[k] = lis[l]; lis[l] = _p; ++k; --l; } return true; } public static bool NextPermutation<T>(IList<T> lis) => NextPermutation(lis, Comparer<T>.Default.Compare); } public class PriorityQueue<T> { List<T> _item; public int Count { get { return _item.Count; } } bool _isascend { get; set; } public T Peek { get { return _item[0]; } } Comparison<T> Comp; public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null) : this(Comparer<T>.Default.Compare, IsAscend, list) {} public PriorityQueue(Comparison<T> cmp, bool IsAscend = true, IEnumerable<T> list = null) { _item = new List<T>(); _isascend = IsAscend; this.Comp = cmp; if (list != null) { _item.AddRange(list); Build(); } } private int Compare(int i, int j) => (_isascend ? -1 : 1) * Comp(_item[i], _item[j]); private void Swap(int i, int j) { var t = _item[i]; _item[i] = _item[j]; _item[j] = t; } private int Parent(int i) => (i - 1) >> 1; private int Left(int i) => (i << 1) + 1; public T Enqueue(T val) { int i = _item.Count; _item.Add(val); while (i > 0) { int p = Parent(i); if (Compare(i, p) > 0) Swap(i, p); i = p; } return val; } private void Heapify(int index) { for (int i = index, j; (j = Left(i)) < _item.Count; i = j) { if (j != _item.Count - 1 && Compare(j, j + 1) < 0) j++; if (Compare(i, j) < 0) Swap(i, j); } } public T Dequeue() { T val = _item[0]; _item[0] = _item[_item.Count - 1]; _item.RemoveAt(_item.Count - 1); Heapify(0); return val; } private void Build() { for (var i = (_item.Count >> 1) - 1; i >= 0; i--) Heapify(i); } public bool Any() => Count > 0; } class Program { static void Main(string[] args) { var CP = new CP(); CP.Solve(); } } public static class Output { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } } public class Input { public static string Str => Console.ReadLine(); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; if (IsTypeEqual<T, char>()) { var list = new List<T>(); foreach (var t in s) { foreach (var u in t) { list.Add(ConvertType<T, char>(char.Parse(u.ToString()))); } } return list.ToArray(); } foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } Queue<string> q = new Queue<string>(); void next() { var ss = Str.Split(' '); foreach (var item in ss) q.Enqueue(item); } public T cin<T>() { if (!q.Any()) next(); return Cast<T>(q.Dequeue()); } public void mul<T>(out T t) { t = cin<T>(); } public void mul<T, U>(out T t, out U u) { t = cin<T>(); u = cin<U>(); } public void mul<T, U, V>(out T t, out U u, out V v) { t = cin<T>(); u = cin<U>(); v = cin<V>(); } public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); } public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); } public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x, out Y y) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); } public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w, out X x, out Y y, out Z z) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); z = cin<Z>(); } public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
3,674
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStr().ToArray(); var bit = new BinaryIndexedTree[26]; for (int i = 0; i < 26; i++) bit[i] = new BinaryIndexedTree(N); for (int i = 0; i < N; i++) { bit[S[i] - 'a'].Add(i + 1, 1); } var list = new List<long>(); var Q = sc.ReadInt(); for (int _ = 0; _ < Q; _++) { var command = sc.ReadInt(); if (command == 1) { var i = sc.ReadInt() - 1; var c = sc.ReadChar(); var prev = S[i] - 'a'; bit[prev].Add(i + 1, -1); bit[c - 'a'].Add(i + 1, 1); S[i] = c; } else { var l = sc.ReadInt(); var r = sc.ReadInt(); var ans = 0L; for (int i = 0; i < 26; i++) { if (bit[i].Sum(l, r) > 0) ans++; } list.Add(ans); } } foreach (var item in list) { Console.WriteLine(item); } } class BinaryIndexedTree { public int N { get; set; } public long[] Array { get; set; } public BinaryIndexedTree(int n) { this.N = n; this.Array = new long[N + 1]; } public void Add(int index, long value) { while (index <= this.N) { this.Array[index] += value; index += index & (-index); } } public long Sum(int l, int r) { return this.Sum(r) - this.Sum(l); } public long Sum(int index) { var sum = 0L; while (index > 0) { sum += this.Array[index]; index -= index & (-index); } return sum; } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStr().ToArray(); var bit = new BinaryIndexedTree[26]; for (int i = 0; i < 26; i++) bit[i] = new BinaryIndexedTree(N); for (int i = 0; i < N; i++) { bit[S[i] - 'a'].Add(i + 1, 1); } var list = new List<long>(); var Q = sc.ReadInt(); for (int _ = 0; _ < Q; _++) { var command = sc.ReadInt(); if (command == 1) { // 更新 var i = sc.ReadInt() - 1; var c = sc.ReadChar(); var prev = S[i] - 'a'; bit[prev].Add(i + 1, -1); bit[c - 'a'].Add(i + 1, 1); S[i] = c; } else { // 計算 var l = sc.ReadInt(); var r = sc.ReadInt(); var ans = 0L; for (int i = 0; i < 26; i++) { if (bit[i].Sum(l, r) > 0) ans++; } list.Add(ans); } } foreach (var item in list) { Console.WriteLine(item); } } class BinaryIndexedTree { public int N { get; set; } public long[] Array { get; set; } public BinaryIndexedTree(int n) { this.N = n; this.Array = new long[N + 1]; } public void Add(int index, long value) { while (index <= this.N) { this.Array[index] += value; index += index & (-index); } } public long Sum(int l, int r) { return this.Sum(r) - this.Sum(l - 1); } public long Sum(int index) { var sum = 0L; while (index > 0) { sum += this.Array[index]; index -= index & (-index); } return sum; } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,463
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC157.E.Cin; using static ABC157.E.Util; using Pair = ABC157.E.VTuple<long, long>; namespace ABC157 { public class E { public static void Main(string[] args) { int N = ri; char[] S = rs.ToArray(); int Q = ri; BinaryIndexedTree[] bits = new BinaryIndexedTree[26]; for (int i = 0; i < 26; i++) { bits[i] = new BinaryIndexedTree(N); } for (int i = 0; i < S.Length; i++) { bits[S[i] - 'a'].Add(i, 1); } DontAutoFlush(); for (int i = 0; i < Q; i++) { int queryType = ri; if (queryType == 1) { int index = ri; char c = rs[0]; bits[c - 'a'].Add(index, 1); bits[S[i] - 'a'].Add(index, -1); S[i] = c; } else { int left = ri - 1; int right = ri - 1; int ans = 0; for (int j = 0; j < 26; j++) { if (bits[j].Sum(left, right) > 0) ans++; } Console.WriteLine(ans); } } Flush(); } /// <summary> /// BIT 0-indexed /// </summary> public class BinaryIndexedTree { long[] Array; int N; public BinaryIndexedTree(int n) { Array = new long[n]; N = n; } /// <summary> /// 各要素をnで初期化する /// </summary> /// <param name="n"></param> public void Init(int n) { for (int i = 0; i < N; i++) { Array[i] = n; } for (int i = 0; i < N; i++) { if ((i | (i + 1)) < N) Array[i | (i + 1)] += Array[i]; } } /// <summary> /// 区間[0,i]の累積和を求める /// </summary> /// <param name="i"></param> /// <returns></returns> public long Sum(int i) { long sum = 0; while (i >= 0) { sum += Array[i]; i = (i & (i + 1)) - 1; } return sum; } /// <summary> /// 区間[i,j]の総和を求める /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> public long Sum(int left, int right) { long l = Sum(left - 1); long r = Sum(right); return r - l; } /// <summary> /// 更新 /// </summary> /// <param name="i"></param> /// <param name="n"></param> public void Add(int i, long n) { while (i < N) { Array[i] += n; i |= i + 1; } } } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC157.E.Cin; using static ABC157.E.Util; using Pair = ABC157.E.VTuple<long, long>; namespace ABC157 { public class E { public static void Main(string[] args) { int N = ri; char[] S = rs.ToArray(); int Q = ri; BinaryIndexedTree[] bits = new BinaryIndexedTree[26]; for (int i = 0; i < 26; i++) { bits[i] = new BinaryIndexedTree(N); } for (int i = 0; i < S.Length; i++) { bits[S[i] - 'a'].Add(i, 1); } DontAutoFlush(); for (int i = 0; i < Q; i++) { int queryType = ri; if (queryType == 1) { int index = ri - 1; char c = rs[0]; bits[c - 'a'].Add(index, 1); bits[S[index] - 'a'].Add(index, -1); S[index] = c; } else { int left = ri - 1; int right = ri - 1; int ans = 0; for (int j = 0; j < 26; j++) { if (bits[j].Sum(left, right) > 0) ans++; } Console.WriteLine(ans); } } Flush(); } /// <summary> /// BIT 0-indexed /// </summary> public class BinaryIndexedTree { long[] Array; int N; public BinaryIndexedTree(int n) { Array = new long[n]; N = n; } /// <summary> /// 各要素をnで初期化する /// </summary> /// <param name="n"></param> public void Init(int n) { for (int i = 0; i < N; i++) { Array[i] = n; } for (int i = 0; i < N; i++) { if ((i | (i + 1)) < N) Array[i | (i + 1)] += Array[i]; } } /// <summary> /// 区間[0,i]の累積和を求める /// </summary> /// <param name="i"></param> /// <returns></returns> public long Sum(int i) { long sum = 0; while (i >= 0) { sum += Array[i]; i = (i & (i + 1)) - 1; } return sum; } /// <summary> /// 区間[i,j]の総和を求める /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> public long Sum(int left, int right) { long l = Sum(left - 1); long r = Sum(right); return r - l; } /// <summary> /// 更新 /// </summary> /// <param name="i"></param> /// <param name="n"></param> public void Add(int i, long n) { while (i < N) { Array[i] += n; i |= i + 1; } } } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22]]
8
4,006
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { var N = sc.Int; var S = sc.Str; var Q = sc.Int; var seg = new SegmentTree<int>(N, 0, (a, b) => a | b); for (int i = 0; i < N; i++) seg[i] = 1 << (S[i] - 'a'); seg.Build(); while (Q-- > 0) { int t = sc.Next<int>(); if (t == 1) { int i; char c; sc.Make(out i, out c); i--; seg.Update(i, 1 << (c - 'a')); } else { int l, r; sc.Make(out l, out r); l--; var n = seg.Query(l, r); var res = 0; for (int i = 0; i < 27; i++) if ((1 & n >> i) == 1) res++; WriteLine(res); } } } } public class SegmentTree<T> { protected readonly T[] dat; protected readonly int sz; protected readonly Func<T, T, T> merge; protected readonly Func<T, T, T> update; protected readonly T id; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Left(int i) => i << 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Right(int i) => (i << 1) | 1; public T this[int i] { get { return dat[i + sz - 1]; } set { dat[i + sz - 1] = value; } } public SegmentTree(int N, T id, Func<T, T, T> merge, Func<T, T, T> update = null) { this.sz = N; this.id = id; this.merge = merge; this.update = update ?? ((T val1, T val2) => val2); dat = Create(N << 1, () => id); } public void Update(int i, T value) { i += sz; dat[i] = update(dat[i], value); while (i > 1) { i >>= 1; dat[i] = merge(dat[Left(i)], dat[Right(i)]); } } public void Build() { for (int i = sz - 1; i > 0; i--) dat[i] = merge(dat[Left(i)], dat[Right(i)]); } public virtual T Query(int left, int right) { T l = id, r = id; for (left += sz, right += sz; left < right; left >>= 1, right >>= 1) { if ((left & 1) == 1) l = merge(l, dat[left++]); if ((right & 1) == 1) r = merge(dat[--right], r); } return merge(l, r); } /// <summary> /// check(func(item[st]...item[i]))がtrueとなる最小のi /// </summary> public int Find(int st, Func<T, bool> check) { var x = id; return Find(st, check, ref x, 0, 0, sz); } private int Find(int st, Func<T, bool> check, ref T x, int k, int l, int r) { if (l + 1 == r) { x = merge(x, dat[k]); return check(x) ? k - sz + 1 : -1; } var m = (l + r) >> 1; if (m <= st) return Find(st, check, ref x, Right(k), m, r); if (st <= l && !check(merge(x, dat[k]))) { x = merge(x, dat[k]); return -1; } var xl = Find(st, check, ref x, Left(k), l, m); if (xl >= 0) return xl; return Find(st, check, ref x, Right(k), m, r); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { var N = sc.Int; var S = sc.Str; var Q = sc.Int; var seg = new SegmentTree<int>(N, 0, (a, b) => a | b); for (int i = 0; i < N; i++) seg[i] = 1 << (S[i] - 'a'); seg.Build(); while (Q-- > 0) { int t = sc.Next<int>(); if (t == 1) { int i; char c; sc.Make(out i, out c); i--; seg.Update(i, 1 << (c - 'a')); } else { int l, r; sc.Make(out l, out r); l--; var n = seg.Query(l, r); var res = 0; for (int i = 0; i < 27; i++) if ((1 & n >> i) == 1) res++; WriteLine(res); } } } } public class SegmentTree<T> { protected readonly T[] dat; protected readonly int sz; protected readonly Func<T, T, T> merge; protected readonly Func<T, T, T> update; protected readonly T id; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Left(int i) => i << 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Right(int i) => (i << 1) | 1; public T this[int i] { get { return dat[i + sz]; } set { dat[i + sz] = value; } } public SegmentTree(int N, T id, Func<T, T, T> merge, Func<T, T, T> update = null) { this.sz = N; this.id = id; this.merge = merge; this.update = update ?? ((T val1, T val2) => val2); dat = Create(N << 1, () => id); } public void Update(int i, T value) { i += sz; dat[i] = update(dat[i], value); while (i > 1) { i >>= 1; dat[i] = merge(dat[Left(i)], dat[Right(i)]); } } public void Build() { for (int i = sz - 1; i > 0; i--) dat[i] = merge(dat[Left(i)], dat[Right(i)]); } public virtual T Query(int left, int right) { T l = id, r = id; for (left += sz, right += sz; left < right; left >>= 1, right >>= 1) { if ((left & 1) == 1) l = merge(l, dat[left++]); if ((right & 1) == 1) r = merge(dat[--right], r); } return merge(l, r); } /// <summary> /// check(func(item[st]...item[i]))がtrueとなる最小のi /// </summary> public int Find(int st, Func<T, bool> check) { var x = id; return Find(st, check, ref x, 0, 0, sz); } private int Find(int st, Func<T, bool> check, ref T x, int k, int l, int r) { if (l + 1 == r) { x = merge(x, dat[k]); return check(x) ? k - sz + 1 : -1; } var m = (l + r) >> 1; if (m <= st) return Find(st, check, ref x, Right(k), m, r); if (st <= l && !check(merge(x, dat[k]))) { x = merge(x, dat[k]); return -1; } var xl = Find(st, check, ref x, Left(k), l, m); if (xl >= 0) return xl; return Find(st, check, ref x, Right(k), m, r); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
2,380
4
using System; namespace ABC157_E___Simple_String_Queries { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var seg = new SegmentTree[26]; for (int i = 0; i < 26; i++) seg[i] = new SegmentTree(N); for (int i = 0; i < N; i++) { seg[S[i] - 'a'].update(i, true); } var Q = int.Parse(Console.ReadLine()); for (int i = 0; i < Q; i++) { var query = Console.ReadLine().Split(' '); if (query[0] == "1") { var index = int.Parse(query[1]); var alphabet = query[2][0] - 'a'; for (int j = 0; j < 26; j++) { seg[j].update(index, alphabet == j); } } else { var left = int.Parse(query[1]) - 1; var right = int.Parse(query[2]); int result = 0; for (int j = 0; j < 26; j++) { if (seg[j].getValue(left, right)) result++; } Console.WriteLine(result); } } } } class SegmentTree { int size; bool[] node; public SegmentTree(int _size) { size = 1; while (size < _size) size *= 2; node = new bool[2 * size - 1]; } public void update(int _index, bool value) { var index = _index + size - 1; node[index] = value; while (index > 0) { index = (index - 1) / 2; node[index] = node[index * 2 + 1] || node[index * 2 + 2]; } } public bool getValue(int requestLeft, int requestRight, int currentIndex = 0, int currentLeft = 0, int currentRight = -1) { if (currentRight < 0) currentRight = size; if (requestLeft >= currentRight || requestRight <= currentLeft) return false; if (requestLeft <= currentLeft && currentRight <= requestRight) return node[currentIndex]; bool childLeft = getValue(requestLeft, requestRight, 2 * currentIndex + 1, currentLeft, (currentLeft + currentRight) / 2); bool childRight = getValue(requestLeft, requestRight, 2 * currentIndex + 2, (currentLeft + currentRight) / 2, currentRight); return childLeft || childRight; } } }
using System; namespace ABC157_E___Simple_String_Queries { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var seg = new SegmentTree[26]; for (int i = 0; i < 26; i++) seg[i] = new SegmentTree(N); for (int i = 0; i < N; i++) { seg[S[i] - 'a'].update(i, true); } var Q = int.Parse(Console.ReadLine()); for (int i = 0; i < Q; i++) { var query = Console.ReadLine().Split(' '); if (query[0] == "1") { var index = int.Parse(query[1]) - 1; var alphabet = query[2][0] - 'a'; for (int j = 0; j < 26; j++) { seg[j].update(index, alphabet == j); } } else { var left = int.Parse(query[1]) - 1; var right = int.Parse(query[2]); int result = 0; for (int j = 0; j < 26; j++) { if (seg[j].getValue(left, right)) result++; } Console.WriteLine(result); } } } } class SegmentTree { int size; bool[] node; public SegmentTree(int _size) { size = 1; while (size < _size) size *= 2; node = new bool[2 * size - 1]; } public void update(int _index, bool value) { var index = _index + size - 1; node[index] = value; while (index > 0) { index = (index - 1) / 2; node[index] = node[index * 2 + 1] || node[index * 2 + 2]; } } public bool getValue(int requestLeft, int requestRight, int currentIndex = 0, int currentLeft = 0, int currentRight = -1) { if (currentRight < 0) currentRight = size; if (requestLeft >= currentRight || requestRight <= currentLeft) return false; if (requestLeft <= currentLeft && currentRight <= requestRight) return node[currentIndex]; bool childLeft = getValue(requestLeft, requestRight, 2 * currentIndex + 1, currentLeft, (currentLeft + currentRight) / 2); bool childRight = getValue(requestLeft, requestRight, 2 * currentIndex + 2, (currentLeft + currentRight) / 2, currentRight); return childLeft || childRight; } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
546
2
using System; using System.Collections.Generic; using System.Linq; public class AtCoderE { static void Main() { int n = int.Parse(Console.ReadLine()); char[] s = Console.ReadLine().ToArray(); BinaryIndexedTree[] counts = new BinaryIndexedTree[26]; for (int i = 0; i < 26; i++) { counts[i] = new BinaryIndexedTree(n); } for (int i = 0; i < n; i++) { int num = StringToInt(s[i]); counts[num].Add(i + 1, 1); } int q = int.Parse(Console.ReadLine()); for (int i = 0; i < q; i++) { var line = Console.ReadLine(); var words = line.Split(' '); int a = int.Parse(words[0]); if (a == 1) { int pos = int.Parse(words[1]); char c = s[pos - 1]; int before = StringToInt(c); int after = StringToInt(words[2][0]); counts[before].Add(pos, -1); counts[after].Add(pos, 1); s[pos - 1] = words[2][0]; } else { int b = int.Parse(words[1]); int c = int.Parse(words[2]); int count = 0; for (int j = 0; j < 26; j++) { if (counts[j].Sum(b - 1, c) > 0) count++; } Console.WriteLine(count); } } } private static int StringToInt(char c) { return c - 'a'; } class BinaryIndexedTree { public int N { get; set; } public long[] Array { get; set; } public BinaryIndexedTree(int n) { this.N = n; this.Array = new long[N + 1]; } public void Add(int index, long value) { while (index <= this.N) { this.Array[index] += value; index += index & (-index); } } public long Sum(int l, int r) { return this.Sum(r) - this.Sum(l - 1); } public long Sum(int index) { var sum = 0L; while (index > 0) { sum += this.Array[index]; index -= index & (-index); } return sum; } } }
using System; using System.Collections.Generic; using System.Linq; public class AtCoderE { static void Main() { int n = int.Parse(Console.ReadLine()); char[] s = Console.ReadLine().ToArray(); BinaryIndexedTree[] counts = new BinaryIndexedTree[26]; for (int i = 0; i < 26; i++) { counts[i] = new BinaryIndexedTree(n); } for (int i = 0; i < n; i++) { int num = StringToInt(s[i]); counts[num].Add(i + 1, 1); } int q = int.Parse(Console.ReadLine()); for (int i = 0; i < q; i++) { var line = Console.ReadLine(); var words = line.Split(' '); int a = int.Parse(words[0]); if (a == 1) { int pos = int.Parse(words[1]); char c = s[pos - 1]; int before = StringToInt(c); int after = StringToInt(words[2][0]); counts[before].Add(pos, -1); counts[after].Add(pos, 1); s[pos - 1] = words[2][0]; } else { int b = int.Parse(words[1]); int c = int.Parse(words[2]); int count = 0; for (int j = 0; j < 26; j++) { if (counts[j].Sum(b, c) > 0) count++; } Console.WriteLine(count); } } } private static int StringToInt(char c) { return c - 'a'; } class BinaryIndexedTree { public int N { get; set; } public long[] Array { get; set; } public BinaryIndexedTree(int n) { this.N = n; this.Array = new long[N + 1]; } public void Add(int index, long value) { while (index <= this.N) { this.Array[index] += value; index += index & (-index); } } public long Sum(int l, int r) { return this.Sum(r) - this.Sum(l - 1); } public long Sum(int index) { var sum = 0L; while (index > 0) { sum += this.Array[index]; index -= index & (-index); } return sum; } } }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
549
2
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static program.Input; using static program.MyMath; using static System.Console; using static program.Const; namespace program { static class Const { public static string alp = "abcdefghijklmnopqrstuvwxyz"; public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const long MOD = 1000000007; public static int INF = int.MaxValue; public static long INFL = long.MaxValue; } class Program { static void Main() { var n = ScanInt(); var s = ScanStr(); var q = ScanInt(); var seg = new SegmentTree(s.ToCharArray()); for (int i = 0; i < q; i++) { var qu = ScanStrArray(); if (qu[0] == "1") { seg.Update(int.Parse(qu[1]), qu[2][0]); } else { WriteLine(seg.Get(int.Parse(qu[1]) - 1, int.Parse(qu[2])).CountBit()); } } } class SegmentTree { int n; long[] node; private Dictionary<char, int> ext = Enumerable.Range(0, alp.Length).ToDictionary(_ => alp[_], _ => _); public SegmentTree(char[] arr) { int size = arr.Length; n = size.Ceiling2(); node = new long[2 * n - 1]; for (int i = 0; i < size; i++) node[i + n - 1] = (1 << ext[arr[i]]); for (int i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] | node[2 * i + 2]; } public void Update(int x, char val) { x += (n - 1); node[x] = 1 << ext[val]; while (x > 0) { x = (x - 1) / 2; node[x] = node[2 * x + 1] | node[2 * x + 2]; } } public long Get(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; var vl = Get(a, b, 2 * k + 1, l, (l + r) / 2); var vr = Get(a, b, 2 * k + 2, (l + r) / 2, r); return vl | vr; } } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } static public string Join<T>(this IEnumerable<T> source, string separator) { return string.Join(separator, source); } static public void Sort(this string[] array) { Array.Sort(array, StringComparer.OrdinalIgnoreCase); } static public void StringSort(this List<string> list) { list.Sort(StringComparer.OrdinalIgnoreCase); } } static class MyMath { static public int CountBit(this long a) { if (a == 0) return 0; int c = 1; for (; a > 1; a /= 2) if (a % 2 == 1) c++; return c; } static public int Floor2(this int a) { int N = 1; while (N < a) N *= 2; return N / 2; } static public long Floor2(this long a) { long N = 1; while (N < a) N *= 2; return N / 2; } static public int Ceiling2(this int a) { int N = 1; while (N < a) N *= 2; return N; } static public long Ceiling2(this long a) { long N = 1; while (N < a) N *= 2; return N; } static public long[] CumSum(this long[] a) { var res = new long[a.Length]; long s = 0; for (int i = 0; i < a.Length; i++) res[i] = (s += a[i]); return res; } static public IEnumerable<int> PrimeFactors(this int n) { int tmp = n; for (int i = 2; i * i <= n; i++) { while (tmp % i == 0) { tmp /= i; yield return i; } } if (tmp != 1) yield return tmp; } static public IEnumerable<long> PrimeFactors(this long n) { var tmp = n; for (long i = 2; i * i <= n; i++) { while (tmp % i == 0) { tmp /= i; yield return i; } } if (tmp != 1) yield return tmp; } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = MOD) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } public static long ModPow(long a, long n, long m = MOD) { long res = 1; while (n > 0) { if (n % 2 == 1) res = (res * a) % m; a = (a * a) % m; n >>= 1; } return res; } } }
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static program.Input; using static program.MyMath; using static System.Console; using static program.Const; namespace program { static class Const { public static string alp = "abcdefghijklmnopqrstuvwxyz"; public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const long MOD = 1000000007; public static int INF = int.MaxValue; public static long INFL = long.MaxValue; } class Program { static void Main() { var n = ScanInt(); var s = ScanStr(); var q = ScanInt(); var seg = new SegmentTree(s.ToCharArray()); for (int i = 0; i < q; i++) { var qu = ScanStrArray(); if (qu[0] == "1") { seg.Update(int.Parse(qu[1]) - 1, qu[2][0]); } else { WriteLine(seg.Get(int.Parse(qu[1]) - 1, int.Parse(qu[2])).CountBit()); } } } class SegmentTree { int n; long[] node; private Dictionary<char, int> ext = Enumerable.Range(0, alp.Length).ToDictionary(_ => alp[_], _ => _); public SegmentTree(char[] arr) { int size = arr.Length; n = size.Ceiling2(); node = new long[2 * n - 1]; for (int i = 0; i < size; i++) node[i + n - 1] = (1 << ext[arr[i]]); for (int i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] | node[2 * i + 2]; } public void Update(int x, char val) { x += (n - 1); node[x] = 1 << ext[val]; while (x > 0) { x = (x - 1) / 2; node[x] = node[2 * x + 1] | node[2 * x + 2]; } } public long Get(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; var vl = Get(a, b, 2 * k + 1, l, (l + r) / 2); var vr = Get(a, b, 2 * k + 2, (l + r) / 2, r); return vl | vr; } } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } static public string Join<T>(this IEnumerable<T> source, string separator) { return string.Join(separator, source); } static public void Sort(this string[] array) { Array.Sort(array, StringComparer.OrdinalIgnoreCase); } static public void StringSort(this List<string> list) { list.Sort(StringComparer.OrdinalIgnoreCase); } } static class MyMath { static public int CountBit(this long a) { if (a == 0) return 0; int c = 1; for (; a > 1; a /= 2) if (a % 2 == 1) c++; return c; } static public int Floor2(this int a) { int N = 1; while (N < a) N *= 2; return N / 2; } static public long Floor2(this long a) { long N = 1; while (N < a) N *= 2; return N / 2; } static public int Ceiling2(this int a) { int N = 1; while (N < a) N *= 2; return N; } static public long Ceiling2(this long a) { long N = 1; while (N < a) N *= 2; return N; } static public long[] CumSum(this long[] a) { var res = new long[a.Length]; long s = 0; for (int i = 0; i < a.Length; i++) res[i] = (s += a[i]); return res; } static public IEnumerable<int> PrimeFactors(this int n) { int tmp = n; for (int i = 2; i * i <= n; i++) { while (tmp % i == 0) { tmp /= i; yield return i; } } if (tmp != 1) yield return tmp; } static public IEnumerable<long> PrimeFactors(this long n) { var tmp = n; for (long i = 2; i * i <= n; i++) { while (tmp % i == 0) { tmp /= i; yield return i; } } if (tmp != 1) yield return tmp; } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = MOD) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } public static long ModPow(long a, long n, long m = MOD) { long res = 1; while (n > 0) { if (n % 2 == 1) res = (res * a) % m; a = (a * a) % m; n >>= 1; } return res; } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
2,042
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n = sc.Int; var s = sc.Str; int q = sc.Int; var sg = new Segtree<int>(n, (x, y) => x | y, 0); for (int i = 0; i < n; i++) { sg.assign(i, 1 << (s[i] - 'a')); } sg.all_update(); for (int _ = 0; _ < q; _++) { var inp = sc.StrArr; if (inp[0] == "1") { int i = int.Parse(inp[1]); int j = inp[2][0] - 'a'; sg.update(i, 1 << j); } else { int l = int.Parse(inp[1]) - 1; int r = int.Parse(inp[2]); int bit = sg.run(l, r); int cnt = 0; for (int i = 0; i < 26; i++) { if (((bit >> i) & 1) == 1) { ++cnt; } } Prt(cnt); } } } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static readonly int M = 1000000007; // public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(params bool[] conds) { foreach (var cond in conds) if (!cond) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b) { a = v[0]; b = v[1]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) { a = v[0]; b = v[1]; c = v[2]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4]; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class Segtree<T> { int n; T[] data; Func<T, T, T> f; T identity; public Segtree(int m, Func<T, T, T> f, T identity) { this.f = f; this.identity = identity; n = 1; while (n < m) n <<= 1; data = new T[(n << 1) - 1]; for (int i = 0; i < data.Length; i++) data[i] = identity; } public Segtree(int m, IList<T> ini, Func<T, T, T> f, T identity) : this(m, f, identity) { for (int i = 0; i < m; ++i) assign(i, ini[i]); all_update(); } public void assign(int j, T x) => data[j + n - 1] = x; public void update(int j, T x) { assign(j, x); update(j); } public void update(int j) { int i = j + n - 1; while (i > 0) { i = i - 1 >> 1; data[i] = f(data[i << 1 | 1], data[i + 1 << 1]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) data[i] = f(data[i << 1 | 1], data[i + 1 << 1]); } public T look(int i) => data[i + n - 1]; // [s, t) public T run(int s, int t) => run(s, t, 0, 0, n); T run(int s, int t, int k, int l, int r) => r <= s || t <= l ? identity : s <= l && r <= t ? data[k] : f(run(s, t, k << 1 | 1, l, l + r >> 1), run(s, t, k + 1 << 1, l + r >> 1, r)); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n = sc.Int; var s = sc.Str; int q = sc.Int; var sg = new Segtree<int>(n, (x, y) => x | y, 0); for (int i = 0; i < n; i++) { sg.assign(i, 1 << (s[i] - 'a')); } sg.all_update(); for (int _ = 0; _ < q; _++) { var inp = sc.StrArr; if (inp[0] == "1") { int i = int.Parse(inp[1]) - 1; int j = inp[2][0] - 'a'; sg.update(i, 1 << j); } else { int l = int.Parse(inp[1]) - 1; int r = int.Parse(inp[2]); int bit = sg.run(l, r); int cnt = 0; for (int i = 0; i < 26; i++) { if (((bit >> i) & 1) == 1) { ++cnt; } } Prt(cnt); } } } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static readonly int M = 1000000007; // public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(params bool[] conds) { foreach (var cond in conds) if (!cond) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b) { a = v[0]; b = v[1]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) { a = v[0]; b = v[1]; c = v[2]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4]; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class Segtree<T> { int n; T[] data; Func<T, T, T> f; T identity; public Segtree(int m, Func<T, T, T> f, T identity) { this.f = f; this.identity = identity; n = 1; while (n < m) n <<= 1; data = new T[(n << 1) - 1]; for (int i = 0; i < data.Length; i++) data[i] = identity; } public Segtree(int m, IList<T> ini, Func<T, T, T> f, T identity) : this(m, f, identity) { for (int i = 0; i < m; ++i) assign(i, ini[i]); all_update(); } public void assign(int j, T x) => data[j + n - 1] = x; public void update(int j, T x) { assign(j, x); update(j); } public void update(int j) { int i = j + n - 1; while (i > 0) { i = i - 1 >> 1; data[i] = f(data[i << 1 | 1], data[i + 1 << 1]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) data[i] = f(data[i << 1 | 1], data[i + 1 << 1]); } public T look(int i) => data[i + n - 1]; // [s, t) public T run(int s, int t) => run(s, t, 0, 0, n); T run(int s, int t, int k, int l, int r) => r <= s || t <= l ? identity : s <= l && r <= t ? data[k] : f(run(s, t, k << 1 | 1, l, l + r >> 1), run(s, t, k + 1 << 1, l + r >> 1, r)); }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
2,875
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = inputs[0]; var k = inputs[1]; var pk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var targetExpectedValues = new double[n]; var sum = 0; var expectedValues = new double[1001]; // すべての種類のサイコロの期待値を事前計算 (pi <= 1000) for (int i = 1; i < 1001; i++) { sum += i; expectedValues[i] = (double)sum / i; } // 与えられた期待値入れる for (int i = 0; i < n; i++) { targetExpectedValues[i] = expectedValues[pk[i]]; } // 累積和 var cSum = new CumulativeSum(targetExpectedValues); // 探す double answer = 0; for (int i = 0; i < n - k; i++) { var s = cSum.GetSum(i, i + k); if (answer < s) answer = s; } Console.WriteLine(answer); } } /// <summary> /// 累積和 /// </summary> public class CumulativeSum { public double[] Array { get; } public CumulativeSum(float[] array) : this(array.Select(t => (double)t).ToArray()) {} public CumulativeSum(double[] array) { var length = array.Length; Array = new double[length + 1]; for (int i = 0; i < length; i++) { Array[i + 1] = array[i] + Array[i]; } } /// <summary> /// left以上right未満の総和 /// </summary> /// <param name="left">以上</param> /// <param name="right">未満</param> public double GetSum(int left, int right) { if (left >= right) return 0; return Array[right] - Array[left]; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = inputs[0]; var k = inputs[1]; var pk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var targetExpectedValues = new double[n]; var sum = 0; var expectedValues = new double[1001]; // すべての種類のサイコロの期待値を事前計算 (pi <= 1000) for (int i = 1; i < 1001; i++) { sum += i; expectedValues[i] = (double)sum / i; } // 与えられた期待値入れる for (int i = 0; i < n; i++) { targetExpectedValues[i] = expectedValues[pk[i]]; } // 累積和 var cSum = new CumulativeSum(targetExpectedValues); // 探す double answer = 0; for (int i = 0; i <= n - k; i++) { var s = cSum.GetSum(i, i + k); if (answer < s) answer = s; } Console.WriteLine(answer); } } /// <summary> /// 累積和 /// </summary> public class CumulativeSum { public double[] Array { get; } public CumulativeSum(float[] array) : this(array.Select(t => (double)t).ToArray()) {} public CumulativeSum(double[] array) { var length = array.Length; Array = new double[length + 1]; for (int i = 0; i < length; i++) { Array[i + 1] = array[i] + Array[i]; } } /// <summary> /// left以上right未満の総和 /// </summary> /// <param name="left">以上</param> /// <param name="right">未満</param> public double GetSum(int left, int right) { if (left >= right) return 0; return Array[right] - Array[left]; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
394
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { static void Main(string[] args) { int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = nk[0]; int k = nk[1]; var s = ReadLine() .Split(' ') .Select(int.Parse) .Select(y => ExpectedValue(y)) .ToList(); var ls = new List<double>(); ls.Add(s[0]); for (int i = 1; i < s.Count; i++) { ls.Add(ls[i - 1] + s[i]); } double ans = 0; for (int i = 0; i < ls.Count - k; i++) { ans = Max(ans, ls[k + i] - ls[i]); } WriteLine(ans); } static double ExpectedValue(int x) { double ans = 0; for (double i = 1; i <= x; i++) { ans += i / x; } return ans; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { static void Main(string[] args) { int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = nk[0]; int k = nk[1]; var s = ReadLine() .Split(' ') .Select(int.Parse) .Select(y => ExpectedValue(y)) .ToList(); var ls = new List<double>(); ls.Add(0); for (int i = 0; i < s.Count; i++) { ls.Add(ls[i] + s[i]); } double ans = 0; for (int i = 0; i < ls.Count - k; i++) { ans = Max(ans, ls[k + i] - ls[i]); } WriteLine(ans); } static double ExpectedValue(int x) { double ans = 0; for (double i = 1; i <= x; i++) { ans += i / x; } return ans; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
278
7
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { //文字列を読み込む int[] line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = line[0]; int K = line[1]; int[] Pk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); //最大値をとインデックスを格納する変数 int sum = 0; int max = -1; for (int i = 0; i < N; i++) { sum += Pk[i]; if (i >= K) { sum -= Pk[i - K]; } if (sum > max) { max = sum; } } /* サイコロの目nに対する期待値は(n+1)/2(= n/2 + 1/2)である。 よって、期待値の合計は、max/2 + K/2(=(max-K)/2 + K)になっている。 可能な限り除算の回数を減らす。 */ double answer = K + (max - K) / 2; //出力 Console.WriteLine(answer); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { //文字列を読み込む int[] line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = line[0]; int K = line[1]; int[] Pk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); //最大値をとインデックスを格納する変数 double sum = 0; double max = -1; for (int i = 0; i < N; i++) { sum += Pk[i]; if (i >= K) { sum -= Pk[i - K]; } if (sum > max) { max = sum; } } /* サイコロの目nに対する期待値は(n+1)/2(= n/2 + 1/2)である。 よって、期待値の合計は、max/2 + K/2(=(max-K)/2 + K)になっている。 可能な限り除算の回数を減らす。 */ double answer = K + (max - K) / 2; //出力 Console.WriteLine(answer); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
201
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { string[] NK = Console.ReadLine().Split(' '); int N = int.Parse(NK[0]); int K = int.Parse(NK[1]); string[] s = Console.ReadLine().Split(' '); int[] p = new int[s.Length + 1]; int sum = 0; for (int i = 1; i < p.Length; i++) { sum += int.Parse(s[i]); p[i] = sum; } double max = 0; for (int i = 0; i < p.Length - K; i++) { if (max < p[i + K] - p[i]) { max = p[i + K] - p[i]; } } max = (max + K) / 2; Console.WriteLine(max); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { string[] NK = Console.ReadLine().Split(' '); int N = int.Parse(NK[0]); int K = int.Parse(NK[1]); string[] s = Console.ReadLine().Split(' '); int[] p = new int[s.Length + 1]; int sum = 0; for (int i = 1; i < p.Length; i++) { sum += int.Parse(s[i - 1]); p[i] = sum; } double max = 0; for (int i = 0; i < p.Length - K; i++) { if (max < p[i + K] - p[i]) { max = p[i + K] - p[i]; } } max = (max + K) / 2; Console.WriteLine(max); } } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
239
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_D.Lib_IO; using static Contest_D.Lib_Minifunc; public static class Contest_D { public static void Main() { checked{ long n, k; Lib_IO.rm(out n, out k); ll[] p ; ra(out p); double e = 0.0; for (int i = 0; i < k; i++) { e += (p[i]+1.0)*0.5; } double ans = 0; for (int i = (int)k; i < n; i++) { e += (p[i]+1.0)*0.5 - (p[i-k]+1.0)*0.5; chmax(ref ans, e); } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_D.Lib_IO; using static Contest_D.Lib_Minifunc; public static class Contest_D { public static void Main() { checked{ long n, k; Lib_IO.rm(out n, out k); ll[] p ; ra(out p); double e = 0.0; for (int i = 0; i < k; i++) { e += (p[i]+1.0)*0.5; } double ans = e; for (int i = (int)k; i < n; i++) { e += (p[i]+1.0)*0.5 - (p[i-k]+1.0)*0.5; chmax(ref ans, e); } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
2,999
2
using System; using System.Linq; class Program { static void Main(string[] args) { // 入力 double[] nk = Console.ReadLine().Split().Select(double.Parse).ToArray(); double[] p = Console.ReadLine().Split().Select(double.Parse).ToArray(); double ans = 0; //出目1-1000の期待値を求める double[] ex = new double[1001]; ex[0] = 0; for (int i = 1; i <= 1000; i++) { double goukei = (1 + i) * i / 2; double heikin = goukei / i; ex[i] = heikin; } for (int i = 0; i < nk[1]; i++) { ans += ex[i]; } double tmp2 = ans; for (int i = 0; i < nk[0] - nk[1]; i++) { tmp2 -= ex[(int)p[i]]; tmp2 += ex[(int)p[i + (int)nk[1]]]; ans = Math.Max(ans, tmp2); } Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { // 入力 double[] nk = Console.ReadLine().Split().Select(double.Parse).ToArray(); double[] p = Console.ReadLine().Split().Select(double.Parse).ToArray(); double ans = 0; //出目1-1000の期待値を求める double[] ex = new double[1001]; ex[0] = 0; for (int i = 1; i <= 1000; i++) { double goukei = (1 + i) * i / 2; double heikin = goukei / i; ex[i] = heikin; } for (int i = 0; i < nk[1]; i++) { ans += ex[(int)p[i]]; } double tmp2 = ans; for (int i = 0; i < nk[0] - nk[1]; i++) { tmp2 -= ex[(int)p[i]]; tmp2 += ex[(int)p[i + (int)nk[1]]]; ans = Math.Max(ans, tmp2); } Console.WriteLine(ans); } }
[["+", 12, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["+", 206, 207, 0, 28, 0, 74, 51, 204, 205, 22], ["+", 0, 28, 0, 74, 51, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 74, 51, 204, 206, 207, 0, 73]]
8
250
6
using System; using System.Linq; public class Hello { public static void Main() { var s = Console.ReadLine().Split(); var n = int.Parse(s[0]); var k = int.Parse(s[1]); var p = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); var pexp = new double[n]; var spex = new double[n + 1]; var ans = 0.0; spex[0] = 0; for (var i = 0; i < n; i++) { pexp[i] = (1.0 + (double)p[i]) / 2.0; spex[i + 1] = pexp[i] + spex[i]; if (i >= k) { if (ans < spex[i + 1] - spex[i + 1 - k]) ans = spex[i + 1] - spex[i + 1 - k]; } } Console.WriteLine(ans); } }
using System; using System.Linq; public class Hello { public static void Main() { var s = Console.ReadLine().Split(); var n = int.Parse(s[0]); var k = int.Parse(s[1]); var p = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); var pexp = new double[n]; var spex = new double[n + 1]; var ans = 0.0; spex[0] = 0; for (var i = 0; i < n; i++) { pexp[i] = (1.0 + (double)p[i]) / 2.0; spex[i + 1] = pexp[i] + spex[i]; if (i + 1 >= k) { if (ans < spex[i + 1] - spex[i + 1 - k]) ans = spex[i + 1] - spex[i + 1 - k]; } } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
225
2
using System; using System.Linq; namespace AtCoderBiginnerContest154 { class Program { static void Main(string[] args) { var numbers = ReadIntArray(); var inputs = ReadIntArray(); var totals = new int[numbers[0]]; totals[0] = inputs[0]; for (var i = 1; i < numbers[0]; i++) { if (i < numbers[1]) { totals[i] = totals[i - 1] + inputs[i]; } else { totals[i] = totals[i - 1] + inputs[i] - inputs[i - numbers[1]]; } } var max = totals.Skip(numbers[1]).Max(); var index = numbers[0] - 1; while (totals[index] != max) { index--; } var expect = 0d; for (var i = index - numbers[1] + 1; i <= index; i++) { var tmp = inputs[i]; expect += tmp * (tmp + 1) / (double)(2 * tmp); } Console.WriteLine(expect); } public static int ReadInt() => int.Parse(Console.ReadLine()); public static int[] ReadIntArray() => Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); public static long ReadLong() => long.Parse(Console.ReadLine()); public static long[] ReadLongArray() => Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => Console.ReadLine().Split(); } }
using System; using System.Linq; namespace AtCoderBiginnerContest154 { class Program { static void Main(string[] args) { var numbers = ReadIntArray(); var inputs = ReadIntArray(); var totals = new long[numbers[0]]; totals[0] = inputs[0]; for (var i = 1; i < numbers[0]; i++) { if (i < numbers[1]) { totals[i] = totals[i - 1] + inputs[i]; } else { totals[i] = totals[i - 1] + inputs[i] - inputs[i - numbers[1]]; } } var max = totals.Skip(numbers[1] - 1).Max(); var index = numbers[0] - 1; while (totals[index] != max) { index--; } var expect = 0d; for (var i = index - numbers[1] + 1; i <= index; i++) { var tmp = inputs[i]; expect += tmp * (tmp + 1) / (double)(2 * tmp); } Console.WriteLine(expect); } public static int ReadInt() => int.Parse(Console.ReadLine()); public static int[] ReadIntArray() => Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); public static long ReadLong() => long.Parse(Console.ReadLine()); public static long[] ReadLongArray() => Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => Console.ReadLine().Split(); } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
381
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace A { class Solver { public void Solve() { var s = sc.Str; var k = sc.Int; var n = s.Length; var dp = new int[n + 1, n + 1, 2]; dp[0, 0, 0] = 0; dp[0, 0, 1] = 1; for (int i = 1; i <= n; i++) { var digit = (int)(s[i - 1] - '0'); var digit0 = digit == 0 ? 0 : 1; var digit19 = digit > 0 ? digit - 1 : 0; dp[i, 0, 0] = 1; dp[i, 0, 1] = 0; for (int j = 1; j <= k; j++) { dp[i, j, 0] = dp[i - 1, j, 0] * 1 + dp[i - 1, j - 1, 0] * 9 + dp[i - 1, j - 1, 1] * digit19 + dp[i - 1, j, 1] * digit0; dp[i, j, 1] = digit == 0 ? dp[i - 1, j, 1] : dp[i - 1, j - 1, 1]; } } var res = dp[n, k, 0] + dp[n, k, 1]; sw.Write(res); } public Solver(Scanner sc, Printer sw) { this.sc = sc; this.sw = sw; } private readonly Scanner sc; private readonly Printer sw; } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } public string Str => reader.ReadLine().Trim(); public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public string[] StrArray => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); public int[] IntArray => StrArray.Select(int.Parse).ToArray(); public long[] LongArray => StrArray.Select(long.Parse).ToArray(); public double[] DoubleArray => StrArray.Select(double.Parse).ToArray(); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public P2<TX, TY> P2<TX, TY>() => new P2<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public P3<TX, TY, TZ> P3<TX, TY, TZ>() => new P3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public P4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new P4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] EInts(this Scanner scanner, int n) => scanner.EInts((long)n); public static int[] EInts(this Scanner scanner, long n) => scanner.ScanLines<int>(n).ToArray(); public static long[] ELongs(this Scanner scanner, int n) => scanner.ELongs((long)n); public static long[] ELongs(this Scanner scanner, long n) => scanner.ScanLines<long>(n).ToArray(); public static double[] EDoubles(this Scanner scanner, int n) => scanner.EDoubles((long)n); public static double[] EDoubles(this Scanner scanner, long n) => scanner.ScanLines<double>(n).ToArray(); public static string[] EStrs(this Scanner scanner, int n) => scanner.EStrs((long)n); public static string[] EStrs(this Scanner scanner, long n) => scanner.ScanLines<string>(n).ToArray(); private static IEnumerable<T> ScanLines<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static P2<TX, TY>[] EP2<TX, TY>(this Scanner scanner, int n) => scanner.EP2<TX, TY>((long)n); public static P2<TX, TY>[] EP2<TX, TY>(this Scanner scanner, long n) => scanner.ScanLines<TX, TY>(n).ToArray(); private static IEnumerable<P2<TX, TY>> ScanLines<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static P3<TX, TY, TZ>[] EP3<TX, TY, TZ>(this Scanner scanner, int n) => scanner.EP3<TX, TY, TZ>((long)n); public static P3<TX, TY, TZ>[] EP3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanLines<TX, TY, TZ>(n).ToArray(); private static IEnumerable<P3<TX, TY, TZ>> ScanLines<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static P4<TX, TY, TZ, TW>[] EP4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.EP4<TX, TY, TZ, TW>((long)n); public static P4<TX, TY, TZ, TW>[] EP4<TX, TY, TZ, TW>(this Scanner scanner, long n) => scanner.ScanLines<TX, TY, TZ, TW>(n).ToArray(); private static IEnumerable<P4<TX, TY, TZ, TW>> ScanLines<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class P2<TX, TY> { public TX X { get; } public TY Y { get; } public P2(TX x, TY y) { this.X = x; this.Y = y; } } class P3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public P3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class P4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public P4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(object obj) { writer.WriteLine(obj.ToString()); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : Console.In; var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); throw e; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace A { class Solver { public void Solve() { var s = sc.Str; var k = sc.Int; var n = s.Length; var dp = new int[n + 1, k + 1, 2]; dp[0, 0, 0] = 0; dp[0, 0, 1] = 1; for (int i = 1; i <= n; i++) { var digit = (int)(s[i - 1] - '0'); var digit0 = digit == 0 ? 0 : 1; var digit19 = digit > 0 ? digit - 1 : 0; dp[i, 0, 0] = 1; dp[i, 0, 1] = 0; for (int j = 1; j <= k; j++) { dp[i, j, 0] = dp[i - 1, j, 0] * 1 + dp[i - 1, j - 1, 0] * 9 + dp[i - 1, j - 1, 1] * digit19 + dp[i - 1, j, 1] * digit0; dp[i, j, 1] = digit == 0 ? dp[i - 1, j, 1] : dp[i - 1, j - 1, 1]; } } var res = dp[n, k, 0] + dp[n, k, 1]; sw.Write(res); } public Solver(Scanner sc, Printer sw) { this.sc = sc; this.sw = sw; } private readonly Scanner sc; private readonly Printer sw; } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } public string Str => reader.ReadLine().Trim(); public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public string[] StrArray => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); public int[] IntArray => StrArray.Select(int.Parse).ToArray(); public long[] LongArray => StrArray.Select(long.Parse).ToArray(); public double[] DoubleArray => StrArray.Select(double.Parse).ToArray(); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public P2<TX, TY> P2<TX, TY>() => new P2<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public P3<TX, TY, TZ> P3<TX, TY, TZ>() => new P3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public P4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new P4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] EInts(this Scanner scanner, int n) => scanner.EInts((long)n); public static int[] EInts(this Scanner scanner, long n) => scanner.ScanLines<int>(n).ToArray(); public static long[] ELongs(this Scanner scanner, int n) => scanner.ELongs((long)n); public static long[] ELongs(this Scanner scanner, long n) => scanner.ScanLines<long>(n).ToArray(); public static double[] EDoubles(this Scanner scanner, int n) => scanner.EDoubles((long)n); public static double[] EDoubles(this Scanner scanner, long n) => scanner.ScanLines<double>(n).ToArray(); public static string[] EStrs(this Scanner scanner, int n) => scanner.EStrs((long)n); public static string[] EStrs(this Scanner scanner, long n) => scanner.ScanLines<string>(n).ToArray(); private static IEnumerable<T> ScanLines<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static P2<TX, TY>[] EP2<TX, TY>(this Scanner scanner, int n) => scanner.EP2<TX, TY>((long)n); public static P2<TX, TY>[] EP2<TX, TY>(this Scanner scanner, long n) => scanner.ScanLines<TX, TY>(n).ToArray(); private static IEnumerable<P2<TX, TY>> ScanLines<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static P3<TX, TY, TZ>[] EP3<TX, TY, TZ>(this Scanner scanner, int n) => scanner.EP3<TX, TY, TZ>((long)n); public static P3<TX, TY, TZ>[] EP3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanLines<TX, TY, TZ>(n).ToArray(); private static IEnumerable<P3<TX, TY, TZ>> ScanLines<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static P4<TX, TY, TZ, TW>[] EP4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.EP4<TX, TY, TZ, TW>((long)n); public static P4<TX, TY, TZ, TW>[] EP4<TX, TY, TZ, TW>(this Scanner scanner, long n) => scanner.ScanLines<TX, TY, TZ, TW>(n).ToArray(); private static IEnumerable<P4<TX, TY, TZ, TW>> ScanLines<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class P2<TX, TY> { public TX X { get; } public TY Y { get; } public P2(TX x, TY y) { this.X = x; this.Y = y; } } class P3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public P3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class P4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public P4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(object obj) { writer.WriteLine(obj.ToString()); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : Console.In; var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); throw e; } } } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22]]
8
2,005
2
using System; using System.Linq; using CompLib.Mathematics; using CompLib.Util; public class Program { int R1, C1, R2, C2; ModInt[] F; public void Solve() { var sc = new Scanner(); R1 = sc.NextInt(); C1 = sc.NextInt(); R2 = sc.NextInt(); C2 = sc.NextInt(); F = new ModInt[2000001]; F[0] = 1; for (int i = 1; i <= 2000000; i++) { F[i] = F[i - 1] * i; } ModInt ans = 0; for (int i = R1; i <= R2; i++) { ans += C(C2 + i + 1, C2); ans -= C(C1 + i, C1 - 1); } Console.WriteLine(ans); } ModInt C(int n, int m) { return F[n] * ModInt.Inverse(F[n - m] * F[m]); } public static void Main(string[] args) => new Program().Solve(); } // https://bitbucket.org/camypaper/complib namespace CompLib.Mathematics { #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; // public const long Mod = 998244353; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion #region Binomial Coefficient public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } #endregion } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Linq; using CompLib.Mathematics; using CompLib.Util; public class Program { int R1, C1, R2, C2; ModInt[] F; public void Solve() { var sc = new Scanner(); R1 = sc.NextInt(); C1 = sc.NextInt(); R2 = sc.NextInt(); C2 = sc.NextInt(); F = new ModInt[3000001]; F[0] = 1; for (int i = 1; i <= 3000000; i++) { F[i] = F[i - 1] * i; } ModInt ans = 0; for (int i = R1; i <= R2; i++) { ans += C(C2 + i + 1, C2); ans -= C(C1 + i, C1 - 1); } Console.WriteLine(ans); } ModInt C(int n, int m) { return F[n] * ModInt.Inverse(F[n - m] * F[m]); } public static void Main(string[] args) => new Program().Solve(); } // https://bitbucket.org/camypaper/complib namespace CompLib.Mathematics { #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; // public const long Mod = 998244353; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion #region Binomial Coefficient public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } #endregion } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
1,180
4
using CompLib.Util; using System; public class Program { int R1, R2, C1, C2; ModInt[] Fact; public void Solve() { var sc = new Scanner(); R1 = sc.NextInt(); C1 = sc.NextInt(); R2 = sc.NextInt(); C2 = sc.NextInt(); Fact = new ModInt[500001]; Fact[0] = 1; for (int i = 1; i <= 500000; i++) { Fact[i] = Fact[i - 1] * i; } // f(r,c) = (r+c) C r // rを固定 ModInt ans = 0; for (int i = R1; i <= R2; i++) { ans += Calc(i); } Console.WriteLine(ans); } private ModInt Calc(int r) { return Calc2(r, C2) - Calc2(r, C1 - 1); } // Σ (r+c) C c private ModInt Calc2(int r, int c) { // r = 0 return = c + 1 // r = 1 return 1 + 2 + 3 + 4 ... // パスカルの三角形の r+1,c return C(r + 1 + c, c); } private ModInt C(int r, int c) { return Fact[r] * ModInt.Inverse(Fact[r - c] * Fact[c]); } public static void Main(string[] args) => new Program().Solve(); } #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion namespace CompLib.Util { using System; using System.Linq; class Scanner { private int _index; private string[] _line; const char separator = ' '; public Scanner() { _index = 0; _line = new string[0]; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); } }
using CompLib.Util; using System; public class Program { int R1, R2, C1, C2; ModInt[] Fact; public void Solve() { var sc = new Scanner(); R1 = sc.NextInt(); C1 = sc.NextInt(); R2 = sc.NextInt(); C2 = sc.NextInt(); Fact = new ModInt[5000001]; Fact[0] = 1; for (int i = 1; i <= 5000000; i++) { Fact[i] = Fact[i - 1] * i; } // f(r,c) = (r+c) C r // rを固定 ModInt ans = 0; for (int i = R1; i <= R2; i++) { ans += Calc(i); } Console.WriteLine(ans); } private ModInt Calc(int r) { return Calc2(r, C2) - Calc2(r, C1 - 1); } // Σ (r+c) C c private ModInt Calc2(int r, int c) { // r = 0 return = c + 1 // r = 1 return 1 + 2 + 3 + 4 ... // パスカルの三角形の r+1,c return C(r + 1 + c, c); } private ModInt C(int r, int c) { return Fact[r] * ModInt.Inverse(Fact[r - c] * Fact[c]); } public static void Main(string[] args) => new Program().Solve(); } #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion namespace CompLib.Util { using System; using System.Linq; class Scanner { private int _index; private string[] _line; const char separator = ' '; public Scanner() { _index = 0; _line = new string[0]; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); } }
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
876
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int r1, c1, r2, c2; sc.Make(out r1, out c1, out r2, out c2); ModInt.Build(1001001); ModInt res = 0; c1--; for (int i = r1; i <= r2; i++) res += ModInt.Comb(c2 + i + 1, i + 1) - ModInt.Comb(c1 + i + 1, i + 1); WriteLine(res); } } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac; //階乗 private static ModInt[] inv; //逆数 private static ModInt[] facinv; // 1/(i!) public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = 1; fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(ModInt n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(ModInt n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = fac[n]; calc = calc * facinv[r]; calc = calc * facinv[n - r]; return calc; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int r1, c1, r2, c2; sc.Make(out r1, out c1, out r2, out c2); ModInt.Build(2001001); ModInt res = 0; c1--; for (int i = r1; i <= r2; i++) res += ModInt.Comb(c2 + i + 1, i + 1) - ModInt.Comb(c1 + i + 1, i + 1); WriteLine(res); } } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac; //階乗 private static ModInt[] inv; //逆数 private static ModInt[] facinv; // 1/(i!) public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = 1; fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(ModInt n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(ModInt n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = fac[n]; calc = calc * facinv[r]; calc = calc * facinv[n - r]; return calc; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
2,221
2
using System; namespace ABC154_F___Many_Many_Paths { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var r1 = read[0]; var c1 = read[1]; var r2 = read[2]; var c2 = read[3]; var MOD = 1000000007; Combination.combInit(2000000, MOD); long temp1 = (Combination.combination(r2 + c2 + 2, c2 + 1) + Combination.combination(r1 + c1, c1)) % MOD; long temp2 = (Combination.combination(r2 + c1 + 1, c1) + Combination.combination(r1 + c2 + 1, c2 + 1)) % MOD; long result = (temp1 - temp2) % MOD; result = result < 0 ? result += MOD : result; Console.WriteLine(result); } } static class Combination { static long combMax; static long combMOD; static long[] factorial; static long[] inverse; static long[] factInv; public static void combInit(long _max, long _mod) { combMax = _max; combMOD = _mod; factorial = new long[combMax]; inverse = new long[combMax]; factInv = new long[combMax]; factorial[0] = factorial[1] = 1; factInv[0] = factInv[1] = 1; inverse[1] = 1; for (int i = 2; i < combMax; i++) { factorial[i] = factorial[i - 1] * i % combMOD; inverse[i] = combMOD - inverse[combMOD % i] * (combMOD / i) % combMOD; factInv[i] = factInv[i - 1] * inverse[i] % combMOD; } } public static long combination(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return factorial[n] * (factInv[k] * factInv[n - k] % combMOD) % combMOD; } } }
using System; namespace ABC154_F___Many_Many_Paths { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var r1 = read[0]; var c1 = read[1]; var r2 = read[2]; var c2 = read[3]; var MOD = 1000000007; Combination.combInit(3000000, MOD); long temp1 = (Combination.combination(r2 + c2 + 2, c2 + 1) + Combination.combination(r1 + c1, c1)) % MOD; long temp2 = (Combination.combination(r2 + c1 + 1, c1) + Combination.combination(r1 + c2 + 1, c2 + 1)) % MOD; long result = (temp1 - temp2) % MOD; result = result < 0 ? result += MOD : result; Console.WriteLine(result); } } static class Combination { static long combMax; static long combMOD; static long[] factorial; static long[] inverse; static long[] factInv; public static void combInit(long _max, long _mod) { combMax = _max; combMOD = _mod; factorial = new long[combMax]; inverse = new long[combMax]; factInv = new long[combMax]; factorial[0] = factorial[1] = 1; factInv[0] = factInv[1] = 1; inverse[1] = 1; for (int i = 2; i < combMax; i++) { factorial[i] = factorial[i - 1] * i % combMOD; inverse[i] = combMOD - inverse[combMOD % i] * (combMOD / i) % combMOD; factInv[i] = factInv[i - 1] * inverse[i] % combMOD; } } public static long combination(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return factorial[n] * (factInv[k] * factInv[n - k] % combMOD) % combMOD; } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
430
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var s = sc.Ia; int m = s[2] + s[3] + 10; Cb r = new Cb(m); Mint ans = 0; for (int i = s[0]; i <= s[2]; i++) { ans += r.C1(s[3] + 1 + i + 1 - 2 + 1, i + 1 - 1 + 1) - r.C1(s[1] - 1 + 1 + i + 1 - 2 + 1, i + 1 - 1 + 1); } Console.WriteLine("{0}", ans); } } public struct Mint { const int mod = (int)1e9 + 7; private long d; public Mint(long d) { this.d = d; } public static implicit operator Mint(long d) { return new Mint(d % mod); } public static explicit operator long(Mint d) { return d.d; } public override string ToString() { return d.ToString(); } public static Mint operator +(Mint a, long b) { a.d = (a.d + b) % mod; return a; } public static Mint operator +(Mint a, Mint b) { a.d = (a.d + b.d) % mod; return a; } public static Mint operator -(Mint a, long b) { a.d = (mod + a.d - b) % mod; return a; } public static Mint operator -(Mint a, Mint b) { a.d = (mod + a.d - b.d) % mod; return a; } public static Mint operator *(Mint a, long b) { a.d = (a.d * b) % mod; return a; } public static Mint operator *(Mint a, Mint b) { a.d = (a.d * b.d) % mod; return a; } public static Mint operator /(Mint a, long b) { a.d = (a.d * Mi(b)) % mod; return a; } public static Mint operator /(Mint a, Mint b) { a.d = (a.d * Mi(b.d)) % mod; return a; } private static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long P1(long n, long k) { return n < k ? 0 : (r[n] * Mi(r[n - k])) % mod; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var s = sc.Ia; int m = s[2] + s[3] + 10; Cb r = new Cb(m); Mint ans = 0; for (int i = s[0]; i <= s[2]; i++) { ans += r.C1(s[3] + 1 + i + 1 - 2 + 1, i + 1 - 1 + 1); ans -= r.C1(s[1] - 1 + 1 + i + 1 - 2 + 1, i + 1 - 1 + 1); } Console.WriteLine("{0}", ans); } } public struct Mint { const int mod = (int)1e9 + 7; private long d; public Mint(long d) { this.d = d; } public static implicit operator Mint(long d) { return new Mint(d % mod); } public static explicit operator long(Mint d) { return d.d; } public override string ToString() { return d.ToString(); } public static Mint operator +(Mint a, long b) { a.d = (a.d + b) % mod; return a; } public static Mint operator +(Mint a, Mint b) { a.d = (a.d + b.d) % mod; return a; } public static Mint operator -(Mint a, long b) { a.d = (mod + a.d - b) % mod; return a; } public static Mint operator -(Mint a, Mint b) { a.d = (mod + a.d - b.d) % mod; return a; } public static Mint operator *(Mint a, long b) { a.d = (a.d * b) % mod; return a; } public static Mint operator *(Mint a, Mint b) { a.d = (a.d * b.d) % mod; return a; } public static Mint operator /(Mint a, long b) { a.d = (a.d * Mi(b)) % mod; return a; } public static Mint operator /(Mint a, Mint b) { a.d = (a.d * Mi(b.d)) % mod; return a; } private static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long P1(long n, long k) { return n < k ? 0 : (r[n] * Mi(r[n - k])) % mod; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110]]
8
1,947
4
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { static void Main() { int[] AH = ReadInts; int A = AH[0]; int H = AH[1]; WriteLine(H % A == 0 ? H / A : H / A + 1); ReadLine(); } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long GetInv(long a, long mod) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod) { if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } struct Vector2Int { public Vector2Int(int x, int y) { X = x; Y = y; } public int X; public int Y; public double Magnitude => Math.Sqrt(X * X + Y * Y); public static Vector2Int zero => new Vector2Int(0, 0); public static Vector2Int u => new Vector2Int(0, 1); public static Vector2Int r => new Vector2Int(1, 0); public static Vector2Int d => new Vector2Int(0, -1); public static Vector2Int l => new Vector2Int(-1, 0); public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l }; public static Vector2Int[] AllDirections8 => new Vector2Int[8] { u, r, d, l, u + r, r + d, d + l, l + u }; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X + b.X, a.Y + b.Y); } public static Vector2Int operator -(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X - b.X, a.Y - b.Y); } public static bool operator ==(Vector2Int a, Vector2Int b) { return a.X == b.X && a.Y == b.Y; } public static bool operator !=(Vector2Int a, Vector2Int b) { return a.X != b.X || a.Y != b.Y; } public static Vector2Int operator *(Vector2Int v, int n) { return new Vector2Int(v.X * n, v.Y * n); } public static Vector2Int operator *(int n, Vector2Int v) { return new Vector2Int(v.X * n, v.Y * n); } } struct Vector3Int { public Vector3Int(int x, int y, int z) { X = x; Y = y; Z = z; } public int X; public int Y; public int Z; public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z); public static Vector3Int zero => new Vector3Int(0, 0, 0); public static Vector3Int u => new Vector3Int(0, 1, 0); public static Vector3Int r => new Vector3Int(1, 0, 0); public static Vector3Int d => new Vector3Int(0, -1, 0); public static Vector3Int l => new Vector3Int(-1, 0, 0); public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } public static bool operator ==(Vector3Int a, Vector3Int b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(Vector3Int a, Vector3Int b) { return a.X != b.X || a.Y != b.Y || a.Z != b.Z; } public static Vector3Int operator *(Vector3Int v, int n) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } public static Vector3Int operator *(int n, Vector3Int v) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } } #region Reader static Vector2Int ReadVec2Int { get { string[] s = Console.ReadLine().Split(' '); return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); } } static Vector2Int[] ReadVec2Ints(int n) { List<Vector2Int> list = new List<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Vector2Int(ab[0], ab[1])); } return list.ToArray(); } static HashSet<Vector2Int> ReadVec2IntHash(int n) { HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; hash.Add(new Vector2Int(ab[0], ab[1])); } return hash; } static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static long mod = (int)Pow(10, 9) + 7; }
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { static void Main() { int[] AH = ReadInts; int A = AH[1]; int H = AH[0]; WriteLine(H % A == 0 ? H / A : H / A + 1); ReadLine(); } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long GetInv(long a, long mod) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod) { if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } struct Vector2Int { public Vector2Int(int x, int y) { X = x; Y = y; } public int X; public int Y; public double Magnitude => Math.Sqrt(X * X + Y * Y); public static Vector2Int zero => new Vector2Int(0, 0); public static Vector2Int u => new Vector2Int(0, 1); public static Vector2Int r => new Vector2Int(1, 0); public static Vector2Int d => new Vector2Int(0, -1); public static Vector2Int l => new Vector2Int(-1, 0); public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l }; public static Vector2Int[] AllDirections8 => new Vector2Int[8] { u, r, d, l, u + r, r + d, d + l, l + u }; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X + b.X, a.Y + b.Y); } public static Vector2Int operator -(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X - b.X, a.Y - b.Y); } public static bool operator ==(Vector2Int a, Vector2Int b) { return a.X == b.X && a.Y == b.Y; } public static bool operator !=(Vector2Int a, Vector2Int b) { return a.X != b.X || a.Y != b.Y; } public static Vector2Int operator *(Vector2Int v, int n) { return new Vector2Int(v.X * n, v.Y * n); } public static Vector2Int operator *(int n, Vector2Int v) { return new Vector2Int(v.X * n, v.Y * n); } } struct Vector3Int { public Vector3Int(int x, int y, int z) { X = x; Y = y; Z = z; } public int X; public int Y; public int Z; public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z); public static Vector3Int zero => new Vector3Int(0, 0, 0); public static Vector3Int u => new Vector3Int(0, 1, 0); public static Vector3Int r => new Vector3Int(1, 0, 0); public static Vector3Int d => new Vector3Int(0, -1, 0); public static Vector3Int l => new Vector3Int(-1, 0, 0); public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } public static bool operator ==(Vector3Int a, Vector3Int b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(Vector3Int a, Vector3Int b) { return a.X != b.X || a.Y != b.Y || a.Z != b.Z; } public static Vector3Int operator *(Vector3Int v, int n) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } public static Vector3Int operator *(int n, Vector3Int v) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } } #region Reader static Vector2Int ReadVec2Int { get { string[] s = Console.ReadLine().Split(' '); return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); } } static Vector2Int[] ReadVec2Ints(int n) { List<Vector2Int> list = new List<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Vector2Int(ab[0], ab[1])); } return list.ToArray(); } static HashSet<Vector2Int> ReadVec2IntHash(int n) { HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; hash.Add(new Vector2Int(ab[0], ab[1])); } return hash; } static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static long mod = (int)Pow(10, 9) + 7; }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
8
2,145
4
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var r = ReadSplit(); var H = r[0].ToInt(); var A = r[1].ToInt(); int i = 0; int sum = 0; while (H >= sum) { i++; sum += A; } Write(i - 1); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void Write(object str) { Console.WriteLine(str); Read(); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(this object obj) { return double.Parse(obj.ToString()); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var r = ReadSplit(); var H = r[0].ToInt(); var A = r[1].ToInt(); int i = 0; int sum = 0; while (H > sum) { i++; sum += A; } Write(i); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void Write(object str) { Console.WriteLine(str); Read(); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(this object obj) { return double.Parse(obj.ToString()); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
250
4
using System; using System.Linq; class P { public static void Main() { var n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int count = n[1] / n[0]; Console.WriteLine(n[1] % n[0] == 0 ? count : count + 1); } }
using System; using System.Linq; class P { public static void Main() { var n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int count = n[0] / n[1]; Console.WriteLine(n[0] % n[1] == 0 ? count : count + 1); } }
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
80
8
using System; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); float a = float.Parse(inp[0]); float b = float.Parse(inp[1]); int r = (int)(a / b) + 1; if (a % b == 0) { Console.WriteLine(r); } else { Console.WriteLine(r - 1); } } }
using System; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); float a = float.Parse(inp[0]); float b = float.Parse(inp[1]); int r = (int)(a / b) + 1; if (!(a % b == 0)) { Console.WriteLine(r); } else { Console.WriteLine(r - 1); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 241, 0, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 241, 0, 23, 0, 25]]
8
103
3
using System; class A { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int A = int.Parse(s[1]); if (A == 1) { Console.WriteLine(N); return; } if (N % A == 0) { Console.WriteLine(N % A); return; } Console.WriteLine(N / A + 1); } }
using System; class A { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int A = int.Parse(s[1]); if (A == 1) { Console.WriteLine(N); return; } if (N % A == 0) { Console.WriteLine(N / A); return; } Console.WriteLine(N / A + 1); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
111
2
using System; namespace abca153 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = a % b; if (a < b) Console.WriteLine(1); else if (c > 0) Console.WriteLine(c + 1); if (a % b == 0) Console.WriteLine(a / b); Console.ReadKey(); } } }
using System; namespace abca153 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = a % b; if (a < b) Console.WriteLine(1); else if (c > 0) Console.WriteLine(a / b + 1); if (a % b == 0) Console.WriteLine(a / b); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
8
125
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sample { class Sample { static void Main() { var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int tai = p[0]; int atk = p[1]; for (int i = 0; i < 10000; i++) { if (tai - i * atk < 0) { Console.WriteLine(i); break; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sample { class Sample { static void Main() { var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int tai = p[0]; int atk = p[1]; for (int i = 1; i < 1000000; i++) { if (tai - i * atk <= 0) { Console.WriteLine(i); break; } } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
110
6
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; public class Program { static public void Main(string[] args) { string str = Console.ReadLine(); int[] data = str.Split(' ').Select(x => int.Parse(x)).ToArray(); int n = data[0] / data[1]; int mod = data[0] % data[1]; Console.WriteLine(n + (mod >= 0 ? 1 : 0)); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; public class Program { static public void Main(string[] args) { string str = Console.ReadLine(); int[] data = str.Split(' ').Select(x => int.Parse(x)).ToArray(); int n = data[0] / data[1]; int mod = data[0] % data[1]; Console.WriteLine(n + (mod > 0 ? 1 : 0)); } }
[["-", 0, 16, 12, 23, 0, 41, 15, 16, 17, 20], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 47]]
8
119
2
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var H = input[0]; var A = input[1]; Console.WriteLine(Math.Floor(H / (double)A)); } } }
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var H = input[0]; var A = input[1]; Console.WriteLine(Math.Ceiling(H / (double)A)); } } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
8
80
2
using System; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(); int h = int.Parse(input1[0]); int a = int.Parse(input1[1]); int count = 0; while (h <= 0) { h = h - a; count++; } Console.WriteLine(count); } } }
using System; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(); int h = int.Parse(input1[0]); int a = int.Parse(input1[1]); int count = 0; while (h > 0) { h = h - a; count++; } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47]]
8
97
2
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel.Design; using System.Globalization; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Xml.Schema; using static System.Console; namespace ConsoleApp2 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<int> Slist() { var t = ReadLine(); if (t.Trim().Length == 0) return new List<int>(); return new List<int>(t.Split().Select(int.Parse)); } static void Main(string[] args) { var h = Sarray()[0]; var s = Sarray().Sum(); WriteLine(h >= s ? "Yes" : "No"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel.Design; using System.Globalization; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Xml.Schema; using static System.Console; namespace ConsoleApp2 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<int> Slist() { var t = ReadLine(); if (t.Trim().Length == 0) return new List<int>(); return new List<int>(t.Split().Select(int.Parse)); } static void Main(string[] args) { var h = Sarray()[0]; var s = Sarray().Sum(); WriteLine(h <= s ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19]]
8
226
2
using System; using System.Linq; namespace ConsoleApp12 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); uint H = uint.Parse(input[0]); uint N = uint.Parse(input[1]); int[] A = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int A_sum = A.Sum(); if (A_sum >= N) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Linq; namespace ConsoleApp12 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); uint H = uint.Parse(input[0]); uint N = uint.Parse(input[1]); int[] A = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int A_sum = A.Sum(); if (A_sum >= H) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
143
2
using System; using System.Collections.Generic; using System.Linq; static class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); //入力 var list = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var list2 = Console.ReadLine().Split(' ').Select(int.Parse); if (list[0] < list2.Sum()) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Out.Flush(); } }
using System; using System.Collections.Generic; using System.Linq; static class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); //入力 var list = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var list2 = Console.ReadLine().Split(' ').Select(int.Parse); if (list[0] <= list2.Sum()) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Out.Flush(); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
155
2
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int h, sum; sum = 0; string[] i = Console.ReadLine().Split(' '); h = int.Parse(i[0]); string[] a = Console.ReadLine().Split(' '); foreach (string s in a) { sum = sum + int.Parse(s); } if (sum > h) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int h, sum; sum = 0; string[] i = Console.ReadLine().Split(' '); h = int.Parse(i[0]); string[] a = Console.ReadLine().Split(' '); foreach (string s in a) { sum = sum + int.Parse(s); } if (sum >= h) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
128
2
using System; using System.Linq; public class B { public static void Main() { int h = int.Parse(Console.ReadLine().Split(' ')[0]); var a = Console.ReadLine().Split(' ').Select(int.Parse); Console.WriteLine((h <= a.Sum()) ? "YES" : "NO"); } }
using System; using System.Linq; public class B { public static void Main() { long h = long.Parse(Console.ReadLine().Split(' ')[0]); var a = Console.ReadLine().Split(' ').Select(long.Parse); Console.WriteLine((h <= a.Sum()) ? "Yes" : "No"); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
91
10
using System; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] array = line.Split(' '); //モンスターの数 int n = int.Parse(array[0]); //使用可能な必殺技の数 int k = int.Parse(array[1]); // HP string li = Console.ReadLine(); string[] ar = li.Split(' '); int[] arr = new int[n]; for (int index = 0; index < n; index++) { int num = int.Parse(ar[index]); arr[index] = num; } //体力の多い順にソート Array.Sort(arr); //残りのモンスターHPの合計 int sum = 0; for (int i = 0; i < arr.Length - k; i++) { sum += arr[i]; } //使った必殺技の数+残HPの合計 Console.WriteLine(sum); } } }
using System; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] array = line.Split(' '); //モンスターの数 int n = int.Parse(array[0]); //使用可能な必殺技の数 int k = int.Parse(array[1]); // HP string li = Console.ReadLine(); string[] ar = li.Split(' '); int[] arr = new int[n]; for (int index = 0; index < n; index++) { int num = int.Parse(ar[index]); arr[index] = num; } //体力の多い順にソート Array.Sort(arr); //残りのモンスターHPの合計 long sum = 0; for (int i = 0; i < arr.Length - k; i++) { sum += arr[i]; } //使った必殺技の数+残HPの合計 Console.WriteLine(sum); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
193
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string[] original_enemy = Console.ReadLine().Split(); int enemy = int.Parse(original_enemy[0]); int special_attack = int.Parse(original_enemy[1]); string[] original_hp = Console.ReadLine().Split(); int[] hp = original_hp.Select(int.Parse).ToArray(); Array.Sort(hp); Array.Reverse(hp); if (special_attack > hp.Length) { special_attack = hp.Length; } for (int i = 0; i < special_attack; i++) { hp[i] = 0; } Console.WriteLine(hp.Sum()); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string[] original_enemy = Console.ReadLine().Split(); int enemy = int.Parse(original_enemy[0]); int special_attack = int.Parse(original_enemy[1]); string[] original_hp = Console.ReadLine().Split(); long[] hp = original_hp.Select(long.Parse).ToArray(); Array.Sort(hp); Array.Reverse(hp); if (special_attack > hp.Length) { special_attack = hp.Length; } for (int i = 0; i < special_attack; i++) { hp[i] = 0; } Console.WriteLine(hp.Sum()); Console.Read(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
190
4
using System; using System.Linq; using static System.Console; class P { public static void Main() { var n = ReadLine().Split().Select(int.Parse).ToArray(); var enemy = ReadLine().Split().Select(long.Parse).OrderBy(a => a).Skip(n[1]).Sum(); WriteLine(enemy); } }
using System; using System.Linq; using static System.Console; class P { public static void Main() { var n = ReadLine().Split().Select(int.Parse).ToArray(); var enemy = ReadLine().Split().Select(long.Parse).OrderBy(a => -a).Skip(n[1]).Sum(); WriteLine(enemy); } }
[["+", 3, 4, 0, 28, 0, 218, 8, 241, 0, 33]]
8
90
1
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var line = System.Console.ReadLine(); var l = line.Split(' '); var N = int.Parse(l[0]); var K = int.Parse(l[1]); var line2 = System.Console.ReadLine(); var l2 = line2.Split(' '); int[] H = new int[N]; for (int i = 0; i < N; i++) { H[i] = int.Parse(l2[i]); } Array.Sort(H); var sum = 0; for (int i = 0; i < N - K; i++) { sum += H[i]; } Console.Write("{0}", sum); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var line = System.Console.ReadLine(); var l = line.Split(' '); var N = int.Parse(l[0]); var K = int.Parse(l[1]); var line2 = System.Console.ReadLine(); var l2 = line2.Split(' '); ulong[] H = new ulong[N]; for (int i = 0; i < N; i++) { H[i] = ulong.Parse(l2[i]); } Array.Sort(H); ulong sum = 0; for (int i = 0; i < N - K; i++) { sum += H[i]; } Console.Write("{0}", sum); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
201
8
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var K = cin.ReadInt; var ans = 0; if (N > K) { var array = new int[N]; for (var i = 0; i < N; i++) { array[i] = cin.ReadInt; } Array.Sort(array); for (var i = 0; i < N - K; i++) { ans += array[i]; } } WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var K = cin.ReadLong; long ans = 0; if (N > K) { var array = new long[N]; for (var i = 0; i < N; i++) { array[i] = cin.ReadLong; } Array.Sort(array); for (var i = 0; i < N - K; i++) { ans += array[i]; } } WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
8
522
10
using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var h = Array.ConvertAll(line, int.Parse); if (k >= n) { Console.WriteLine(0); goto exit; } long ans = h.OrderByDescending(x => x).Skip(k).Sum(x => x); Console.WriteLine(ans); exit:; } }
using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var h = Array.ConvertAll(line, long.Parse); if (k >= n) { Console.WriteLine(0); goto exit; } var ans = h.OrderByDescending(x => x).Skip(k).Sum((x => x)); Console.WriteLine(ans); exit:; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 23, 0, 25]]
8
154
6
using System; class FennecVsMonster { static void Main(string[] args) { string[] line1 = System.Console.ReadLine().Trim().Split(' '); string[] line2 = System.Console.ReadLine().Trim().Split(' '); int[] H = new int[int.Parse(line1[0])]; for (int i = 0; i < int.Parse(line1[0]); i++) { H[i] = int.Parse(line2[i]); } Array.Sort(H); int A = 0; for (int i = 0; i < (int.Parse(line1[0]) - int.Parse(line1[1])); i++) { A = A + H[i]; } System.Console.WriteLine(A); } }
using System; class FennecVsMonster { static void Main(string[] args) { string[] line1 = System.Console.ReadLine().Trim().Split(' '); string[] line2 = System.Console.ReadLine().Trim().Split(' '); long[] H = new long[int.Parse(line1[0])]; for (int i = 0; i < int.Parse(line1[0]); i++) { H[i] = long.Parse(line2[i]); } Array.Sort(H); long A = 0; for (int i = 0; i < (int.Parse(line1[0]) - int.Parse(line1[1])); i++) { A = A + H[i]; } System.Console.WriteLine(A); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
190
8
using System; using System.Linq; using System.Collections.Generic; namespace abc153 { class Program { static void Main(string[] args) { var n = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var h = Console.ReadLine().Split().Select(s => int.Parse(s)).ToList(); // var remove = n[0] - n[1]; var ans = h.OrderByDescending(o => o).Skip(n[1]).Sum(); Console.WriteLine(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace abc153 { class Program { static void Main(string[] args) { var n = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var h = Console.ReadLine().Split().Select(s => long.Parse(s)).ToList(); long ans = h.OrderByDescending(o => o).Skip(n[1]).Sum(); Console.WriteLine(ans); } } }
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
124
4
using System; using System.Collections.Generic; class Program { static void Main() { var n = Array.ConvertAll(Console.ReadLine().Split(), ulong.Parse); var p = Array.ConvertAll(Console.ReadLine().Split(), ulong.Parse); Array.Sort(p); ulong sum = 0; for (ulong i = n[0] - 1; i > 0; i--) { if (i > n[0] - 1 - n[1]) { sum += p[i]; } } Console.WriteLine(sum); } }
using System; using System.Collections.Generic; class Program { static void Main() { var n = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); var p = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); Array.Sort(p); long sum = 0; for (long i = n[0] - 1; i >= 0; i--) { if (i <= n[0] - 1 - n[1]) { sum += p[i]; } } Console.WriteLine(sum); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
130
12
using System; using System.Linq; namespace ABC152C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (input[0] <= input[1]) Console.WriteLine("0"); var monsters = Console.ReadLine() .Split(' ') .Select(long.Parse) .OrderByDescending(i => i) .Skip(input[1]) .ToArray(); Console.WriteLine(monsters.Sum()); } } }
using System; using System.Linq; namespace ABC152C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (input[0] <= input[1]) { Console.WriteLine("0"); return; } var monsters = Console.ReadLine() .Split(' ') .Select(long.Parse) .OrderByDescending(i => i) .Skip(input[1]) .ToArray(); Console.WriteLine(monsters.Sum()); } } }
[["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
128
4
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); int ans = 0; while (N > 0) { N /= 2; ans = ans * 2 + 1; } Console.WriteLine(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long ans = 0; while (N > 0) { N /= 2; ans = ans * 2 + 1; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
80
2
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { var h = long.Parse(Console.ReadLine()); var i = 1; if (h <= 2) { Console.WriteLine("1"); return; } while (h > 1) { i += 1; h = h / 2; } if (i == 1) { Console.WriteLine("1"); return; } long g = 1; for (var n = 0; n < i; n++) { g *= 2; } Console.WriteLine(g - 1); } }
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { var h = long.Parse(Console.ReadLine()); var i = 1; if (h <= 1) { Console.WriteLine("1"); return; } while (h > 1) { i += 1; h = h / 2; } if (i == 1) { Console.WriteLine("1"); return; } long g = 1; for (var n = 0; n < i; n++) { g *= 2; } Console.WriteLine(g - 1); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
135
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoders { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var H = inputArray[0]; //答えの出力 var ans = getAns(H); Console.WriteLine(ans); } /// <summary> // 必要な攻撃の最小回数は、2^x <= H < 2^(x+1) となる // 2^xがHの時と同じ回数になる // 2^(x+1)のHを0にするのに必要な回数は、2^(x)のHを0にするのに必要な回数をkとすると、2k+1になる // f(x) = sum(2^(i))... i=0~x-1 であることが帰納法で示せる /// </summary> /// <param name="H"></param> /// <returns></returns> private static int getAns(long H) { if (H == 1) { return 1; } //まずxを求める var x = 0; while (Math.Pow(2, x + 1) <= H) { x++; } // Console.WriteLine($"x={x}"); var ans = 1; var exp2 = 1; for (int i = 0; i < x; i++) { exp2 *= 2; ans += exp2; } return ans; } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoders { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var H = inputArray[0]; //答えの出力 var ans = getAns(H); Console.WriteLine(ans); } /// <summary> // 必要な攻撃の最小回数は、2^x <= H < 2^(x+1) となる // 2^xがHの時と同じ回数になる // 2^(x+1)のHを0にするのに必要な回数は、2^(x)のHを0にするのに必要な回数をkとすると、2k+1になる // f(x) = sum(2^(i))... i=0~x-1 であることが帰納法で示せる /// </summary> /// <param name="H"></param> /// <returns></returns> private static long getAns(long H) { if (H == 1) { return 1; } //まずxを求める var x = 0; while (Math.Pow(2, x + 1) <= H) { x++; } // Console.WriteLine($"x={x}"); long ans = 1; long exp2 = 1; for (int i = 0; i < x; i++) { exp2 *= 2; ans += exp2; } return ans; } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
[["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
284
6
using System; class Program { public static void Main() { long n = int.Parse(Console.ReadLine()); long sum = 0; double count = 0; do { n = n / 2; sum += (long)Math.Pow(2.0, count); count++; } while (n >= 1); Console.WriteLine(sum); } }
using System; class Program { public static void Main() { long n = long.Parse(Console.ReadLine()); long sum = 0; double count = 0; do { n = n / 2; sum += (long)Math.Pow(2.0, count); count++; } while (n >= 1); Console.WriteLine(sum); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
79
2
using System; using System.Linq; namespace ABC153D { class Program { static void Main(string[] args) { long h = int.Parse(Console.ReadLine()); string h2 = Convert.ToString(h, 2); Console.WriteLine(Math.Pow(2, h2.Length) - 1); } } }
using System; using System.Linq; namespace ABC153D { class Program { static void Main(string[] args) { long h = long.Parse(Console.ReadLine()); string h2 = Convert.ToString(h, 2); Console.WriteLine(Math.Pow(2, h2.Length) - 1); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
71
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var H = long.Parse(Console.ReadLine()); var monsters = (long)1; var answer = (long)monsters; while (H > 1) { H /= 2; monsters *= 2; } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var H = long.Parse(Console.ReadLine()); var monsters = (long)1; var answer = (long)monsters; while (H > 1) { H /= 2; monsters *= 2; answer += monsters; } Console.WriteLine(answer); } } }
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
173
4
using System; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); double hp = double.Parse(inp[0]); double count = 1; double count2 = 0; while (true) { if (hp <= 1) { count2++; break; } else { hp /= 2d; } count2 += Math.Pow(2, count); count++; } Console.WriteLine(count2); } }
using System; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); long hp = long.Parse(inp[0]); double count = 1; double count2 = 0; while (true) { if (hp <= 1) { count2++; break; } else { hp /= 2; } count2 += Math.Pow(2, count); count++; } Console.WriteLine(count2); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 250], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
8
104
6
using System; class Program { static void Main(string[] args) { Console.WriteLine( Math.Pow( 2, 1 + Math.Floor(Math.Log(2, double.Parse(Console.ReadLine())))) - 1); } }
using System; class Program { static void Main(string[] args) { Console.WriteLine( Math.Pow( 2, 1 + Math.Floor(Math.Log(double.Parse(Console.ReadLine()), 2))) - 1); } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
57
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { static void Main(string[] args) { long H = int.Parse(Console.ReadLine()); for (int i = 0; i < 50; i++) { long pow = (long)Math.Pow(2, i); if (H < pow) { Console.WriteLine(pow - 1); break; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { static void Main(string[] args) { long H = long.Parse(Console.ReadLine()); for (int i = 0; i < 50; i++) { long pow = (long)Math.Pow(2, i); if (H < pow) { Console.WriteLine(pow - 1); break; } } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
110
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var H = sc.ReadInt(); var N = sc.ReadInt(); var A = new int[N]; var B = new int[N]; for (int i = 0; i < N; i++) { A[i] = sc.ReadInt(); B[i] = sc.ReadInt(); } var dp = new int[H + 1]; for (int i = 0; i < dp.Length; i++) { dp[i] = int.MaxValue; } dp[0] = 0; for (int i = 0; i < dp.Length; i++) { if (dp[i] == int.MaxValue) continue; for (int j = 0; j < N; j++) { var a = A[i]; var b = B[i]; var ni = Math.Min(H, i + a); dp[ni] = Math.Min(dp[ni], dp[i] + b); } } var ans = dp[H]; Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var H = sc.ReadInt(); var N = sc.ReadInt(); var A = new int[N]; var B = new int[N]; for (int i = 0; i < N; i++) { A[i] = sc.ReadInt(); B[i] = sc.ReadInt(); } var dp = new int[H + 1]; for (int i = 0; i < dp.Length; i++) { dp[i] = int.MaxValue; } dp[0] = 0; for (int i = 0; i < dp.Length; i++) { if (dp[i] == int.MaxValue) continue; for (int j = 0; j < N; j++) { var a = A[j]; var b = B[j]; var ni = Math.Min(H, i + a); dp[ni] = Math.Min(dp[ni], dp[i] + b); } } var ans = dp[H]; Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22]]
8
1,234
4
using System; namespace kozaiyApp { public class CrestedIbisVsMonster { static void Main() { string[] input = Console.ReadLine().Split(' '); int H = int.Parse(input[0]); // モンスター体力 int N = int.Parse(input[1]); // まほう種類 int[][] AB = new int [N][]; // A奪う体力 B奪われる体力 for (int i = 0; i < N; i++) { AB[i] = new int[2]; string[] inputMagic = Console.ReadLine().Split(' '); AB[i] = Array.ConvertAll(inputMagic, int.Parse); } // Aの低い順にソート Array.Sort(AB, (a, b) => a[0] - b[0]); // Bの低い順にソート Array.Sort(AB, (a, b) => a[1] - b[1]); int[,] DP = new int[N, H + 1]; for (int i = 0; i < N; i++) // まほうの種類 { for (int j = 0; j <= H; j++) // モンスター体力 { if (j == 0) { DP[i, j] = 0; continue; } if (i == 0) { if (j <= AB[i][0]) { DP[i, j] = AB[i][1]; continue; } double r = (double)j / AB[i][0]; int R = Convert.ToInt32(Math.Ceiling(r)); DP[i, j] = R * AB[i][1]; continue; } // 前行の値 int p = DP[i - 1, j]; // jがAより大きい場合はB+前行のj-A、jがAより小さい場合はBを返す int q = j > AB[i][0] ? AB[i][1] + DP[i - 1, j - AB[i][0]] : AB[i][1]; // pとq小さい方 DP[i, j] = Math.Min(p, q); } } Console.WriteLine(DP[N - 1, H]); } } }
using System; namespace kozaiyApp { public class CrestedIbisVsMonster { static void Main() { string[] input = Console.ReadLine().Split(' '); int H = int.Parse(input[0]); // モンスター体力 int N = int.Parse(input[1]); // まほう種類 int[][] AB = new int [N][]; // A奪う体力 B奪われる体力 for (int i = 0; i < N; i++) { AB[i] = new int[2]; string[] inputMagic = Console.ReadLine().Split(' '); AB[i] = Array.ConvertAll(inputMagic, int.Parse); } // Aの低い順にソート Array.Sort(AB, (a, b) => a[0] - b[0]); // Bの低い順にソート Array.Sort(AB, (a, b) => a[1] - b[1]); int[,] DP = new int[N, H + 1]; for (int i = 0; i < N; i++) // まほうの種類 { for (int j = 0; j <= H; j++) // モンスター体力 { if (j == 0) { DP[i, j] = 0; continue; } if (i == 0) { if (j <= AB[i][0]) { DP[i, j] = AB[i][1]; continue; } double r = (double)j / AB[i][0]; int R = Convert.ToInt32(Math.Ceiling(r)); DP[i, j] = R * AB[i][1]; continue; } // 前行の値 int p = DP[i - 1, j]; // j>A の場合は B+残りスペース(今の行のj-A) // ※同じまほうが複数回使えるため前行ではなく今の行を見る int q = j > AB[i][0] ? AB[i][1] + DP[i, j - AB[i][0]] : AB[i][1]; // pとq小さい方 DP[i, j] = Math.Min(p, q); } } Console.WriteLine(DP[N - 1, H]); } } }
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
439
2
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace abc153 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc153E(); } public static void solve_abc153E() { int[] hn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int h = hn[0]; int n = hn[1]; List<KeyValuePair<int, int>> pairs = new List<KeyValuePair<int, int>>(); for (int i = 0; i < n; i++) { int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int a = ab[0]; int b = ab[1]; pairs.Add(new KeyValuePair<int, int>(a, b)); } int[] dp = new int[h + 1]; dp[0] = 0; for (int i = 1; i < h + 1; i++) { dp[i] = 10000000; } for (int i = 1; i < h + 1; i++) { for (int j = 0; j < pairs.Count; j++) { dp[i] = Math.Min(dp[i], dp[Math.Max(i - pairs[j].Key, 0)] + pairs[j].Value); } } Console.WriteLine(dp[h]); } public static void solve_abc153D() { long h = Convert.ToInt64(Console.ReadLine()); long k = 1; long cnt = 0; while (h > 0) { h /= 2; cnt += k; k *= 2; } Console.WriteLine(cnt); } public static void solve_abc153C() { int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int n = nk[0]; int k = nk[1]; int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Array.Sort(h, (a, b) => b.CompareTo(a)); long cnt = 0; for (int i = k; i < n; i++) { cnt += h[i]; } Console.WriteLine(cnt); } public static void solve_abc153B() { int[] hn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int h = hn[0]; int n = hn[1]; int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); for (int i = 0; i < n; i++) { h -= a[i]; } if (h <= 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public static void solve_abc153A() { int[] ha = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine((ha[0] + ha[1] - 1) / ha[1]); } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace abc153 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc153E(); } public static void solve_abc153E() { int[] hn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int h = hn[0]; int n = hn[1]; List<KeyValuePair<int, int>> pairs = new List<KeyValuePair<int, int>>(); for (int i = 0; i < n; i++) { int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int a = ab[0]; int b = ab[1]; pairs.Add(new KeyValuePair<int, int>(a, b)); } int[] dp = new int[h + 1]; dp[0] = 0; for (int i = 1; i < h + 1; i++) { dp[i] = 1000000000; } for (int i = 1; i < h + 1; i++) { for (int j = 0; j < pairs.Count; j++) { dp[i] = Math.Min(dp[i], dp[Math.Max(i - pairs[j].Key, 0)] + pairs[j].Value); } } Console.WriteLine(dp[h]); } public static void solve_abc153D() { long h = Convert.ToInt64(Console.ReadLine()); long k = 1; long cnt = 0; while (h > 0) { h /= 2; cnt += k; k *= 2; } Console.WriteLine(cnt); } public static void solve_abc153C() { int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int n = nk[0]; int k = nk[1]; int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Array.Sort(h, (a, b) => b.CompareTo(a)); long cnt = 0; for (int i = k; i < n; i++) { cnt += h[i]; } Console.WriteLine(cnt); } public static void solve_abc153B() { int[] hn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int h = hn[0]; int n = hn[1]; int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); for (int i = 0; i < n; i++) { h -= a[i]; } if (h <= 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public static void solve_abc153A() { int[] ha = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine((ha[0] + ha[1] - 1) / ha[1]); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
718
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public class Magic { public int Index { get; set; } public int Damage { get; set; } public int Cost { get; set; } } public static void Main(string[] args) { var p = Input().ToInt(); var h = p[0]; var n = p[1]; var magics = new Magic[n]; for (int i = 0; i < n; i++) { p = Input().ToInt(); magics[i] = new Magic() { Index = i, Damage = p[0], Cost = p[1] }; } var dp = new long[h + 1, n + 1]; //相手のモンスターを体力hにするための最小コスト for (int i = 0; i < h + 1; i++) for (int j = 0; j < n + 1; j++) // nokori tairyoku dp[i, j] = 9999999; for (int i = 0; i < n + 1; i++) dp[h, i] = 0; for (int i = h; i >= 0; i--) { for (int j = 0; j < n; j++) { var m = magics[j]; dp[Math.Max(0, i - m.Damage), j] = Math.Min(dp[Math.Max(0, i - m.Damage), j], dp[i, j] + m.Cost); dp[i, j + 1] = Math.Min(dp[i, j], dp[i, j + 1]); } } long min = 999999999; for (int i = 0; i < n; i++) { min = Math.Min(min, dp[0, i]); } Console.WriteLine(min); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public class Magic { public int Index { get; set; } public int Damage { get; set; } public int Cost { get; set; } } public static void Main(string[] args) { var p = Input().ToInt(); var h = p[0]; var n = p[1]; var magics = new Magic[n]; for (int i = 0; i < n; i++) { p = Input().ToInt(); magics[i] = new Magic() { Index = i, Damage = p[0], Cost = p[1] }; } var dp = new long[h + 1, n + 1]; //相手のモンスターを体力hにするための最小コスト for (int i = 0; i < h + 1; i++) for (int j = 0; j < n + 1; j++) dp[i, j] = 99999999999; for (int i = 0; i < n + 1; i++) dp[h, i] = 0; for (int i = h; i > 0; i--) { for (int j = 0; j < n; j++) { var m = magics[j]; dp[Math.Max(0, i - m.Damage), j] = Math.Min(dp[Math.Max(0, i - m.Damage), j], dp[i, j] + m.Cost); dp[i, j + 1] = Math.Min(dp[i, j], dp[i, j + 1]); } } long min = 99999999999; for (int i = 0; i < n + 1; i++) { min = Math.Min(min, dp[0, i]); } Console.WriteLine(min); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["-", 0, 7, 8, 7, 8, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 7, 8, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
641
8
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { String input1 = Console.ReadLine(); String[] input = input1.Split(' '); int h = int.Parse(input[0]); int n = int.Parse(input[1]); int[,] table = new int[n, 2]; int[] dp1 = new int[h + 10]; int[] dp2 = new int[h + 10]; int[] temp = new int[n + 2]; for (int i = 0; i <= h; i++) { dp1[i] = 1000000000; dp2[i] = 1000000000; } dp1[0] = dp2[0] = 0; for (int i = 0; i < n; i++) { String[] input2 = Console.ReadLine().Split(' '); int d = int.Parse(input2[0]); int c = int.Parse(input2[1]); for (int j = 0; j < d; j++) { dp1[j] = Math.Min(dp2[j], c); } for (int j = d; j <= h; j++) { dp1[j] = Math.Min(dp2[j], dp1[j - d] + c); } temp = dp1; dp1 = dp2; dp2 = temp; // Console.WriteLine(dp2[h]); } Console.WriteLine(dp2[h]); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { String input1 = Console.ReadLine(); String[] input = input1.Split(' '); int h = int.Parse(input[0]); int n = int.Parse(input[1]); int[,] table = new int[n, 2]; int[] dp1 = new int[h + 10000]; int[] dp2 = new int[h + 10000]; int[] temp = new int[n + 2]; for (int i = 0; i <= h; i++) { dp1[i] = 1000000000; dp2[i] = 1000000000; } dp1[0] = dp2[0] = 0; for (int i = 0; i < n; i++) { String[] input2 = Console.ReadLine().Split(' '); int d = int.Parse(input2[0]); int c = int.Parse(input2[1]); for (int j = 0; j < d; j++) { dp1[j] = Math.Min(dp2[j], c); } for (int j = d; j <= h; j++) { dp1[j] = Math.Min(dp2[j], dp1[j - d] + c); } temp = dp1; dp1 = dp2; dp2 = temp; // Console.WriteLine(dp2[h]); } Console.WriteLine(dp2[h]); } } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
334
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int H, N; sc.Make(out H, out N); var dp = Create(H + 1, () => int.MaxValue / 2); dp[0] = 0; for (var i = 0; i < N; i++) { int a, b; sc.Make(out a, out b); for (var j = 0; j <= H; j++) { if (j - a < 0) continue; chmin(ref dp[j], dp[j - a] + b); } for (var j = H - a + 1; j <= H; j++) chmin(ref dp[H], dp[j] + b); } WriteLine(dp[H]); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Copy<T>(this T[] A) => Create(A.Length, i => A[i]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Pair<T, U> MP<T, U>(T t, U u) => new Pair<T, U>(t, u); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Pair<T, U, V> MP<T, U, V>(T t, U u, V v) => new Pair<T, U, V>(t, u, v); public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> MP<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> MP<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Tie(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int H, N; sc.Make(out H, out N); var dp = Create(H + 1, () => int.MaxValue / 2); dp[0] = 0; for (var i = 0; i < N; i++) { int a, b; sc.Make(out a, out b); for (var j = 0; j <= H; j++) { if (j - a < 0) continue; chmin(ref dp[j], dp[j - a] + b); } for (var j = Max(0, H - a + 1); j <= H; j++) chmin(ref dp[H], dp[j] + b); } WriteLine(dp[H]); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Copy<T>(this T[] A) => Create(A.Length, i => A[i]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Pair<T, U> MP<T, U>(T t, U u) => new Pair<T, U>(t, u); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Pair<T, U, V> MP<T, U, V>(T t, U u, V v) => new Pair<T, U, V>(t, u, v); public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> MP<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> MP<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Tie(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
[["+", 10, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
1,788
5
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class F { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var (N, D, A) = Scanner.Scan<int, int, int>(); var E = new(int X, long H)[N]; for (var i = 0; i < N; i++) { var (x, h) = Scanner.Scan<int, long>(); E[i] = (x, h); } Array.Sort(E, (x, y) => Comparer<int>.Default.Compare(x.X, y.X)); var counts = new long[N + 1]; var answer = 0L; var current = 0L; for (var i = 0; i < N; i++) { var h = E[i].H; current -= counts[i]; var damage = current * A; h -= damage; if (h <= 0) continue; var count = h / A; if (h % A > 0) count++; current += count; answer += count; var l = i; var r = N; while (r - l > 1) { var m = l + (r - l) / 2; if (E[m].H - E[i].X <= D * 2) l = m; else r = m; } counts[r] += count; } Console.WriteLine(answer); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class F { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var (N, D, A) = Scanner.Scan<int, int, int>(); var E = new(int X, long H)[N]; for (var i = 0; i < N; i++) { var (x, h) = Scanner.Scan<int, long>(); E[i] = (x, h); } Array.Sort(E, (x, y) => Comparer<int>.Default.Compare(x.X, y.X)); var counts = new long[N + 1]; var answer = 0L; var current = 0L; for (var i = 0; i < N; i++) { var h = E[i].H; current -= counts[i]; var damage = current * A; h -= damage; if (h <= 0) continue; var count = h / A; if (h % A > 0) count++; current += count; answer += count; var l = i; var r = N; while (r - l > 1) { var m = l + (r - l) / 2; if (E[m].X - E[i].X <= D * 2) l = m; else r = m; } counts[r] += count; } Console.WriteLine(answer); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
[["-", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22]]
8
730
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; using static AtCoder.CalcL; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1 }; static readonly int[] dJ = { 1, 0, -1, 0 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); var input = cin.ReadSplitInt(); int N = input[0]; int D = input[1]; int A = input[2]; var mon = new List<Tuple<long, long>>(); for (var i = 0; i < N; i++) { var p = cin.ReadSplitInt(); mon.Add(new Tuple<long, long>(p[0], p[1])); } mon.Sort((x, y) => { long dif = x.Item1 - y.Item1; return dif == 0 ? 0 : (dif > 0 ? 1 : -1); }); var b_at = new List<long>(); var b_dm = new List<long>(); b_at.Add(-SINF); b_dm.Add(0); long ans = 0; for (var i = 0; i < N; i++) { long X = mon[i].Item1; long H = mon[i].Item2; int l = 0; int r = b_at.Count(); while (r - l > 1) { int mid = (l + r) / 2; if (b_at[mid] + (2 * D) >= X) { r = mid; } else { l = mid; } } H -= b_dm[b_dm.Count() - 1] - b_dm[l]; if (H <= 0) continue; long num = (H + A - 1) / A; ans += num; b_at.Add(X + (2 * D)); b_dm.Add(b_dm[b_dm.Count() - 1] + (A * num)); } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } static public class CalcI { public static int Gcd(int a, int b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static int Lcm(int a, int b) { int g = Gcd(a, b); return a / g * b; } public static int Ceil(int n, int div) { return (n + div - 1) / div; } } static public class CalcL { public static long Gcd(long a, long b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static long Lcm(long a, long b) { long g = Gcd(a, b); return a / g * b; } public static long Ceil(long n, long div) { return (n + div - 1) / div; } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } public Modulo() {} } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; using static AtCoder.CalcL; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1 }; static readonly int[] dJ = { 1, 0, -1, 0 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); var input = cin.ReadSplitInt(); int N = input[0]; int D = input[1]; int A = input[2]; var mon = new List<Tuple<long, long>>(); for (var i = 0; i < N; i++) { var p = cin.ReadSplitInt(); mon.Add(new Tuple<long, long>(p[0], p[1])); } mon.Sort((x, y) => { long dif = x.Item1 - y.Item1; return dif == 0 ? 0 : (dif > 0 ? 1 : -1); }); // Console.WriteLine(string.Join(",", mon)); var b_at = new List<long>(); var b_dm = new List<long>(); b_at.Add(-SINF); b_dm.Add(0); long ans = 0; for (var i = 0; i < N; i++) { long X = mon[i].Item1; long H = mon[i].Item2; int l = 0; int r = b_at.Count(); while (r - l > 1) { int mid = (l + r) / 2; if (b_at[mid] + (2 * D) >= X) { r = mid; } else { l = mid; } } H -= b_dm[b_dm.Count() - 1] - b_dm[l]; if (H <= 0) continue; long num = (H + A - 1) / A; ans += num; b_at.Add(X); b_dm.Add(b_dm[b_dm.Count() - 1] + (A * num)); } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } static public class CalcI { public static int Gcd(int a, int b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static int Lcm(int a, int b) { int g = Gcd(a, b); return a / g * b; } public static int Ceil(int n, int div) { return (n + div - 1) / div; } } static public class CalcL { public static long Gcd(long a, long b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static long Lcm(long a, long b) { long g = Gcd(a, b); return a / g * b; } public static long Ceil(long n, long div) { return (n + div - 1) / div; } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } public Modulo() {} } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 48], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
1,388
6
using System; using System.Collections.Generic; using System.Linq; using static Input; using static Prog; using NX = System.Int64; public class Solver { public void Solve() { int N = NextInt(); NX D = NextLong() * 2, A = NextLong(); List<Tuple<NX, NX>> input = new List<Tuple<NX, NX>>(); for (int i = 0; i < N; i++) { input.Add(new Tuple<NX, NX>(NextLong(), NextLong())); } var d = input.OrderBy(v => v.Item1).ToList(); LazySegTree LST = new LazySegTree(N, 0, (x, y) => (x + y)); for (int i = 0; i < N; i++) { LST.Insert(i, d[i].Item2); } NX ans = 0; for (int i = 0; i < N; i++) { if (LST.Query(i, i + 1) <= 0) continue; int ok = -1, ng = N; while (ng - ok != 1) { int mid = (ok + ng) / 2; if (d[mid].Item1 - d[i].Item1 <= D) ok = mid; else ng = mid; } // d[i].HP を超えるだけ打つ NX count = LST.Query(i, i + 1) / A + (LST.Query(i, i + 1) % A == 0 ? 0 : 1); // Console.WriteLine(i + " -> " + (ok + 1) + " : " + count); ans += count; LST.InsertRange(i, ok + 1, -count * A); } Console.WriteLine(ans); } } public class LazySegTree { private List<NX> node = new List<NX>(); private List<NX> lazy = new List<NX>(); private static int size = 1; private static NX lim; private static Func<NX, NX, NX> update_func; public LazySegTree(int n, NX m, Func<NX, NX, NX> func) { while (size < n) size *= 2; node = Enumerable.Range(0, 2 * size - 1).Select(v => m).ToList(); lazy = Enumerable.Range(0, 2 * size - 1).Select(v => m).ToList(); lim = m; update_func = func; } public void Insert(int pos, NX val) { pos += size - 1; node[pos] = val; while (pos != 0) { pos = (pos % 2 == 0 ? pos / 2 - 1 : pos / 2); node[pos] = update_func(node[pos * 2 + 1], node[pos * 2 + 2]); } } public void InsertRange(int ser_l, int ser_r, NX val, int index = 0, int now_l = 0, int now_r = 0) { if (2 * size < index) return; if (now_r <= now_l) now_r = size; Convey(index); if (ser_r <= now_l || now_r <= ser_l) return; if (ser_l <= now_l && now_r <= ser_r) { lazy[index] = (now_r - now_l) * val; Convey(index); } else { // Left InsertRange(ser_l, ser_r, val, index * 2 + 1, now_l, (now_l + now_r) / 2); // Reft InsertRange(ser_l, ser_r, val, index * 2 + 2, (now_l + now_r) / 2, now_r); node[index] = update_func(node[index * 2 + 1], node[index * 2 + 2]); } } public NX Query(int sel_l, int sel_r, int index = 0, int now_l = 0, int now_r = 0) { if (now_r <= now_l) now_r = size; if (now_r <= sel_l || sel_r <= now_l) return lim; Convey(index); if (sel_l <= now_l && now_r <= sel_r) { return node[index]; } NX left = Query(sel_l, sel_r, index * 2 + 1, now_l, (now_r + now_l) / 2); NX right = Query(sel_l, sel_r, index * 2 + 2, (now_r + now_l) / 2, now_r); return update_func(left, right); } void Convey(int index) { if (lazy[index] != 0) { node[index] += lazy[index]; if (index < size - 1) { lazy[index * 2 + 1] = lazy[index] / 2; lazy[index * 2 + 2] = lazy[index] / 2; } lazy[index] = 0; } } } public class Prog { public const long MOD = 1000000007; public const int INF = 1000000007; public struct Pair { public int x, y; public Pair(int a, int b) { x = a; y = b; } } static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Solver().Solve(); Console.Out.Flush(); return; } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } public long Abs(long a, long b) => Math.Abs(a - b); }
using System; using System.Collections.Generic; using System.Linq; using static Input; using static Prog; using NX = System.Int64; public class Solver { public void Solve() { int N = NextInt(); NX D = NextLong() * 2, A = NextLong(); List<Tuple<NX, NX>> input = new List<Tuple<NX, NX>>(); for (int i = 0; i < N; i++) { input.Add(new Tuple<NX, NX>(NextLong(), NextLong())); } var d = input.OrderBy(v => v.Item1).ToList(); LazySegTree LST = new LazySegTree(N, 0, (x, y) => (x + y)); for (int i = 0; i < N; i++) { LST.Insert(i, d[i].Item2); } NX ans = 0; for (int i = 0; i < N; i++) { if (LST.Query(i, i + 1) <= 0) continue; int ok = -1, ng = N; while (ng - ok != 1) { int mid = (ok + ng) / 2; if (d[mid].Item1 - d[i].Item1 <= D) ok = mid; else ng = mid; } // d[i].HP を超えるだけ打つ NX count = LST.Query(i, i + 1) / A + (LST.Query(i, i + 1) % A == 0 ? 0 : 1); // Console.WriteLine(d[i].Item1 + " -> " + d[ok].Item1 + " : " + count); ans += count; LST.InsertRange(i, ok + 1, -count * A); } Console.WriteLine(ans); } } public class LazySegTree { private List<NX> node = new List<NX>(); private List<NX> lazy = new List<NX>(); private static int size = 1; private static NX lim; private static Func<NX, NX, NX> update_func; public LazySegTree(int n, NX m, Func<NX, NX, NX> func) { while (size < n) size *= 2; node = Enumerable.Range(0, 2 * size - 1).Select(v => m).ToList(); lazy = Enumerable.Range(0, 2 * size - 1).Select(v => m).ToList(); lim = m; update_func = func; } public void Insert(int pos, NX val) { pos += size - 1; node[pos] = val; while (pos != 0) { pos = (pos % 2 == 0 ? pos / 2 - 1 : pos / 2); node[pos] = update_func(node[pos * 2 + 1], node[pos * 2 + 2]); } } public void InsertRange(int ser_l, int ser_r, NX val, int index = 0, int now_l = 0, int now_r = 0) { if (2 * size < index) return; if (now_r <= now_l) now_r = size; Convey(index); if (ser_r <= now_l || now_r <= ser_l) return; if (ser_l <= now_l && now_r <= ser_r) { lazy[index] += (now_r - now_l) * val; Convey(index); } else { // Left InsertRange(ser_l, ser_r, val, index * 2 + 1, now_l, (now_l + now_r) / 2); // Reft InsertRange(ser_l, ser_r, val, index * 2 + 2, (now_l + now_r) / 2, now_r); node[index] = update_func(node[index * 2 + 1], node[index * 2 + 2]); } } public NX Query(int sel_l, int sel_r, int index = 0, int now_l = 0, int now_r = 0) { if (now_r <= now_l) now_r = size; if (now_r <= sel_l || sel_r <= now_l) return lim; Convey(index); if (sel_l <= now_l && now_r <= sel_r) { return node[index]; } NX left = Query(sel_l, sel_r, index * 2 + 1, now_l, (now_r + now_l) / 2); NX right = Query(sel_l, sel_r, index * 2 + 2, (now_r + now_l) / 2, now_r); return update_func(left, right); } void Convey(int index) { if (lazy[index] != 0) { node[index] += lazy[index]; if (index < size - 1) { lazy[index * 2 + 1] += lazy[index] / 2; lazy[index * 2 + 2] += lazy[index] / 2; } lazy[index] = 0; } } } public class Prog { public const long MOD = 1000000007; public const int INF = 1000000007; public struct Pair { public int x, y; public Pair(int a, int b) { x = a; y = b; } } static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Solver().Solve(); Console.Out.Flush(); return; } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } public long Abs(long a, long b) => Math.Abs(a - b); }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
1,387
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC153F { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var D = NN; var A = NN; var XHList = Repeat(0, N).Select(_ => new { X = NN, H = NN }).ToArray(); var tree = new LIB_RedBlackTree<long, long, long>( 0, 0, (x, y) => x + y, (x, y) => x + y, (x, y) => x + y); foreach (var item in XHList) { tree.Add(item.X, item.H); } var ans = 0L; for (var i = 0; i < N; i++) { var x = tree[i].Key; var v = tree[i].Value; if (v == 0) continue; var needCnt = (v - 1) / A + 1; if (needCnt == 0) continue; tree.Update(i, tree.UpperBound(x + 2 * D), -needCnt * A); ans += needCnt; } Console.WriteLine(ans); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_RedBlackTree { public struct SumEntity { public long s; public long c; } static public LIB_RedBlackTree<long, long, long> CreateRUQRmQ() => new LIB_RedBlackTree<long, long, long>(long.MaxValue, long.MaxValue, Math.Min, (x, y) => y, (x, y) => y); static public LIB_RedBlackTree<long, long, long> CreateRAQRmQ() => new LIB_RedBlackTree<long, long, long>(long.MaxValue, 0, Math.Min, (x, y) => x + y, (x, y) => x + y); static public LIB_RedBlackTree<long, long, long> CreateRUQRMQ() => new LIB_RedBlackTree<long, long, long>(long.MinValue, long.MinValue, Math.Max, (x, y) => y, (x, y) => y); static public LIB_RedBlackTree<long, long, long> CreateRAQRMQ() => new LIB_RedBlackTree<long, long, long>(long.MinValue, 0, Math.Max, (x, y) => x + y, (x, y) => x + y); static public LIB_RedBlackTree<long, SumEntity, long> CreateRUQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>( new SumEntity { c = 0, s = 0 }, long.MaxValue, (x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s }, (x, y) => new SumEntity { c = x.c, s = x.c * y }, (x, y) => y); static public LIB_RedBlackTree<long, SumEntity, long> CreateRAQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>( new SumEntity { c = 0, s = 0 }, 0, (x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s }, (x, y) => new SumEntity { c = x.c, s = x.s + x.c * y }, (x, y) => x + y); } class LIB_RedBlackTree<Key, ValueT, ValueE> { bool ope; class Node { public Node left; public Node right; public Key key; public ValueT val; public ValueT dat; public ValueE lazy; public bool isBlack; public int cnt; public bool needRecalc; } Func<ValueT, ValueT, ValueT> f; Func<ValueT, ValueE, ValueT> g; Func<ValueE, ValueE, ValueE> h; ValueT ti; ValueE ei; Comparison<Key> c; Node root; bool isNeedFix; Node lmax; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f, Func<ValueT, ValueE, ValueT> g, Func<ValueE, ValueE, ValueE> h, Comparison<Key> c, bool ope = true) { this.ti = ti; this.ei = ei; this.f = f; this.g = g; this.h = h; this.c = c; this.ope = ope; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f, Func<ValueT, ValueE, ValueT> g, Func<ValueE, ValueE, ValueE> h) : this(ti, ei, f, g, h, Comparer<Key>.Default.Compare) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IsRed(Node n) => n != null && !n.isBlack; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IsBlack(Node n) => n != null && n.isBlack; [MethodImpl(MethodImplOptions.AggressiveInlining)] int Cnt(Node n) => n?.cnt ?? 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] void Eval(Node n) { if (n == null || ei.Equals(n.lazy)) return; n.val = g(n.val, n.lazy); if (!n.needRecalc) n.dat = g(n.dat, n.lazy); if (n.left != null) n.left.lazy = h(n.left.lazy, n.lazy); if (n.right != null) n.right.lazy = h(n.right.lazy, n.lazy); n.lazy = ei; } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Recalc(Node n) { if (n == null) return; Eval(n); if (!n.needRecalc) return; n.needRecalc = false; n.dat = n.val; if (n.left != null) { Recalc(n.left); n.dat = f(n.left.dat, n.dat); } if (n.right != null) { Recalc(n.right); n.dat = f(n.dat, n.right.dat); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateL(Node n) { if (ope) { Eval(n); Eval(n.right); } Node m = n.right, t = m.left; m.left = n; n.right = t; n.cnt -= m.cnt - Cnt(t); m.cnt += n.cnt - Cnt(t); if (ope) { n.needRecalc = true; m.needRecalc = true; } return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateR(Node n) { if (ope) { Eval(n); Eval(n.left); } Node m = n.left, t = m.right; m.right = n; n.left = t; n.cnt -= m.cnt - Cnt(t); m.cnt += n.cnt - Cnt(t); if (ope) { n.needRecalc = true; m.needRecalc = true; } return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateLR(Node n) { n.left = RotateL(n.left); return RotateR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateRL(Node n) { n.right = RotateR(n.right); return RotateL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(Key key, ValueT val) { root = Add(root, key, val); root.isBlack = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Add(Node n, Key key, ValueT val) { if (n == null) { isNeedFix = true; return new Node() { key = key, val = val, dat = val, lazy = ei, cnt = 1 }; } if (ope) Eval(n); if (c(key, n.key) < 0) n.left = Add(n.left, key, val); else n.right = Add(n.right, key, val); if (ope) n.needRecalc = true; n.cnt++; return Balance(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Balance(Node n) { if (!isNeedFix) return n; if (!IsBlack(n)) return n; if (IsRed(n.left) && IsRed(n.left.left)) { n = RotateR(n); n.left.isBlack = true; } else if (IsRed(n.left) && IsRed(n.left.right)) { n = RotateLR(n); n.left.isBlack = true; } else if (IsRed(n.right) && IsRed(n.right.left)) { n = RotateRL(n); n.right.isBlack = true; } else if (IsRed(n.right) && IsRed(n.right.right)) { n = RotateL(n); n.right.isBlack = true; } else isNeedFix = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(Key key) { root = Remove(root, key); if (root != null) root.isBlack = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Remove(Node n, Key key) { if (n == null) throw new Exception(); if (ope) Eval(n); n.cnt--; var r = c(key, n.key); if (r < 0) { n.left = Remove(n.left, key); if (ope) n.needRecalc = true; return BalanceL(n); } if (r > 0) { n.right = Remove(n.right, key); if (ope) n.needRecalc = true; return BalanceR(n); } if (n.left == null) { isNeedFix = n.isBlack; return n.right; } n.left = RemoveMax(n.left); n.key = lmax.key; n.val = lmax.val; if (ope) n.needRecalc = true; return BalanceL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RemoveMax(Node n) { if (ope) Eval(n); n.cnt--; if (n.right != null) { n.right = RemoveMax(n.right); if (ope) n.needRecalc = true; return BalanceR(n); } lmax = n; isNeedFix = n.isBlack; return n.left; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BalanceL(Node n) { if (!isNeedFix) return n; if (IsBlack(n.right) && IsRed(n.right.left)) { var b = n.isBlack; n = RotateRL(n); n.isBlack = b; n.left.isBlack = true; isNeedFix = false; } else if (IsBlack(n.right) && IsRed(n.right.right)) { var b = n.isBlack; n = RotateL(n); n.isBlack = b; n.right.isBlack = true; n.left.isBlack = true; isNeedFix = false; } else if (IsBlack(n.right)) { isNeedFix = n.isBlack; n.isBlack = true; n.right.isBlack = false; } else { n = RotateL(n); n.isBlack = true; n.left.isBlack = false; n.left = BalanceL(n.left); isNeedFix = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BalanceR(Node n) { if (!isNeedFix) return n; if (IsBlack(n.left) && IsRed(n.left.right)) { var b = n.isBlack; n = RotateLR(n); n.isBlack = b; n.right.isBlack = true; isNeedFix = false; } else if (IsBlack(n.left) && IsRed(n.left.left)) { var b = n.isBlack; n = RotateR(n); n.isBlack = b; n.left.isBlack = true; n.right.isBlack = true; isNeedFix = false; } else if (IsBlack(n.left)) { isNeedFix = n.isBlack; n.isBlack = true; n.left.isBlack = false; } else { n = RotateR(n); n.isBlack = true; n.right.isBlack = false; n.right = BalanceR(n.right); isNeedFix = false; } return n; } public KeyValuePair<Key, ValueT> this[long i] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return At(root, i); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] KeyValuePair<Key, ValueT> At(Node n, long i) { if (ope) Eval(n); if (n.left == null) { if (i == 0) return new KeyValuePair<Key, ValueT>(n.key, n.val); else return At(n.right, i - 1); } if (n.left.cnt == i) return new KeyValuePair<Key, ValueT>(n.key, n.val); if (n.left.cnt > i) return At(n.left, i); return At(n.right, i - n.left.cnt - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(Key key) { var t = LowerBound(key); return t < Cnt(root) && c(At(root, t).Key, key) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long UpperBound(Key key) => UpperBound(root, key); [MethodImpl(MethodImplOptions.AggressiveInlining)] long UpperBound(Node n, Key key) { if (n == null) return 0; var r = c(key, n.key); if (r < 0) return UpperBound(n.left, key); return Cnt(n.left) + 1 + UpperBound(n.right, key); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LowerBound(Key key) => LowerBound(root, key); [MethodImpl(MethodImplOptions.AggressiveInlining)] long LowerBound(Node n, Key key) { if (n == null) return 0; var r = c(key, n.key); if (r <= 0) return LowerBound(n.left, key); return Cnt(n.left) + 1 + LowerBound(n.right, key); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, ValueT> Min() { Node n = root.left, p = root; while (n != null) { p = n; if (ope) Eval(p); n = n.left; } return new KeyValuePair<Key, ValueT>(p.key, p.val); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, ValueT> Max() { Node n = root.right, p = root; while (n != null) { p = n; if (ope) Eval(p); n = n.right; } return new KeyValuePair<Key, ValueT>(p.key, p.val); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long l, long r, ValueE val) => Update(root, l, r, val); [MethodImpl(MethodImplOptions.AggressiveInlining)] void Update(Node n, long l, long r, ValueE val) { if (n == null) return; Eval(n); n.needRecalc = true; var lc = Cnt(n.left); if (lc < l) Update(n.right, l - lc - 1, r - lc - 1, val); else if (r <= lc) Update(n.left, l, r, val); else if (l <= 0 && Cnt(n) <= r) n.lazy = val; else { n.val = g(n.val, val); if (l < lc) Update(n.left, l, lc, val); if (lc + 1 < r) Update(n.right, 0, r - lc - 1, val); } return; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueT Query(long l, long r) => Query(root, l, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] ValueT Query(Node n, long l, long r) { var v1 = ti; var v2 = ti; var v3 = ti; if (n == null) return ti; Eval(n); var lc = Cnt(n.left); if (lc < l) v3 = Query(n.right, l - lc - 1, r - lc - 1); else if (r <= lc) v1 = Query(n.left, l, r); else if (l <= 0 && Cnt(n) <= r) { Recalc(n); v2 = n.dat; } else { if (l < lc) v1 = Query(n.left, l, lc); if (lc + 1 < r) v3 = Query(n.right, 0, r - lc - 1); v2 = n.val; } return f(f(v1, v2), v3); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => root != null; public long Count => Cnt(root); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<KeyValuePair<Key, ValueT>> List() => L(root); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<KeyValuePair<Key, ValueT>> L(Node n) { if (n == null) yield break; foreach (var i in L(n.left)) yield return i; yield return new KeyValuePair<Key, ValueT>(n.key, n.val); foreach (var i in L(n.right)) yield return i; } } class LIB_RedBlackTree<Key, Value> { LIB_RedBlackTree<Key, Value, Value> tree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(Comparison<Key> c) { tree = new LIB_RedBlackTree<Key, Value, Value>( default(Value), default(Value), (x, y) => x, (x, y) => x, (x, y) => x, c, false); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree() : this(Comparer<Key>.Default.Compare) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(Key key, Value val) => tree.Add(key, val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(Key key) => tree.Remove(key); public KeyValuePair<Key, Value> this[long i] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return tree[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(Key key) => tree.Have(key); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long UpperBound(Key key) => tree.UpperBound(key); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LowerBound(Key key) => tree.LowerBound(key); [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, Value> Min() => tree.Min(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, Value> Max() => tree.Max(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => tree.Any(); public long Count => tree.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<KeyValuePair<Key, Value>> List() => tree.List(); } class LIB_RedBlackTree<T> { LIB_RedBlackTree<T, T, T> tree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(Comparison<T> c) { tree = new LIB_RedBlackTree<T, T, T>(default(T), default(T), (x, y) => x, (x, y) => x, (x, y) => x, c, false); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree() : this(Comparer<T>.Default.Compare) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T val) => tree.Add(val, val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T val) => tree.Remove(val); public T this[long i] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return tree[i].Key; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T val) => tree.Have(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long UpperBound(T val) => tree.UpperBound(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LowerBound(T val) => tree.LowerBound(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() => tree.Min().Key; [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() => tree.Max().Key; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => tree.Any(); public long Count => tree.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => tree.List().Select(e => e.Key); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC153F { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var D = NN; var A = NN; var XHList = Repeat(0, N).Select(_ => new { X = NN, H = NN }).ToArray(); var tree = new LIB_RedBlackTree<long, long, long>( 0, 0, (x, y) => x + y, (x, y) => x + y, (x, y) => x + y); foreach (var item in XHList) { tree.Add(item.X, item.H); } var ans = 0L; for (var i = 0; i < N; i++) { var x = tree[i].Key; var v = tree[i].Value; if (v <= 0) continue; var needCnt = (v - 1) / A + 1; if (needCnt == 0) continue; tree.Update(i, tree.UpperBound(x + 2 * D), -needCnt * A); ans += needCnt; } Console.WriteLine(ans); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_RedBlackTree { public struct SumEntity { public long s; public long c; } static public LIB_RedBlackTree<long, long, long> CreateRUQRmQ() => new LIB_RedBlackTree<long, long, long>(long.MaxValue, long.MaxValue, Math.Min, (x, y) => y, (x, y) => y); static public LIB_RedBlackTree<long, long, long> CreateRAQRmQ() => new LIB_RedBlackTree<long, long, long>(long.MaxValue, 0, Math.Min, (x, y) => x + y, (x, y) => x + y); static public LIB_RedBlackTree<long, long, long> CreateRUQRMQ() => new LIB_RedBlackTree<long, long, long>(long.MinValue, long.MinValue, Math.Max, (x, y) => y, (x, y) => y); static public LIB_RedBlackTree<long, long, long> CreateRAQRMQ() => new LIB_RedBlackTree<long, long, long>(long.MinValue, 0, Math.Max, (x, y) => x + y, (x, y) => x + y); static public LIB_RedBlackTree<long, SumEntity, long> CreateRUQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>( new SumEntity { c = 0, s = 0 }, long.MaxValue, (x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s }, (x, y) => new SumEntity { c = x.c, s = x.c * y }, (x, y) => y); static public LIB_RedBlackTree<long, SumEntity, long> CreateRAQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>( new SumEntity { c = 0, s = 0 }, 0, (x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s }, (x, y) => new SumEntity { c = x.c, s = x.s + x.c * y }, (x, y) => x + y); } class LIB_RedBlackTree<Key, ValueT, ValueE> { bool ope; class Node { public Node left; public Node right; public Key key; public ValueT val; public ValueT dat; public ValueE lazy; public bool isBlack; public int cnt; public bool needRecalc; } Func<ValueT, ValueT, ValueT> f; Func<ValueT, ValueE, ValueT> g; Func<ValueE, ValueE, ValueE> h; ValueT ti; ValueE ei; Comparison<Key> c; Node root; bool isNeedFix; Node lmax; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f, Func<ValueT, ValueE, ValueT> g, Func<ValueE, ValueE, ValueE> h, Comparison<Key> c, bool ope = true) { this.ti = ti; this.ei = ei; this.f = f; this.g = g; this.h = h; this.c = c; this.ope = ope; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f, Func<ValueT, ValueE, ValueT> g, Func<ValueE, ValueE, ValueE> h) : this(ti, ei, f, g, h, Comparer<Key>.Default.Compare) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IsRed(Node n) => n != null && !n.isBlack; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IsBlack(Node n) => n != null && n.isBlack; [MethodImpl(MethodImplOptions.AggressiveInlining)] int Cnt(Node n) => n?.cnt ?? 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] void Eval(Node n) { if (n == null || ei.Equals(n.lazy)) return; n.val = g(n.val, n.lazy); if (!n.needRecalc) n.dat = g(n.dat, n.lazy); if (n.left != null) n.left.lazy = h(n.left.lazy, n.lazy); if (n.right != null) n.right.lazy = h(n.right.lazy, n.lazy); n.lazy = ei; } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Recalc(Node n) { if (n == null) return; Eval(n); if (!n.needRecalc) return; n.needRecalc = false; n.dat = n.val; if (n.left != null) { Recalc(n.left); n.dat = f(n.left.dat, n.dat); } if (n.right != null) { Recalc(n.right); n.dat = f(n.dat, n.right.dat); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateL(Node n) { if (ope) { Eval(n); Eval(n.right); } Node m = n.right, t = m.left; m.left = n; n.right = t; n.cnt -= m.cnt - Cnt(t); m.cnt += n.cnt - Cnt(t); if (ope) { n.needRecalc = true; m.needRecalc = true; } return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateR(Node n) { if (ope) { Eval(n); Eval(n.left); } Node m = n.left, t = m.right; m.right = n; n.left = t; n.cnt -= m.cnt - Cnt(t); m.cnt += n.cnt - Cnt(t); if (ope) { n.needRecalc = true; m.needRecalc = true; } return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateLR(Node n) { n.left = RotateL(n.left); return RotateR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RotateRL(Node n) { n.right = RotateR(n.right); return RotateL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(Key key, ValueT val) { root = Add(root, key, val); root.isBlack = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Add(Node n, Key key, ValueT val) { if (n == null) { isNeedFix = true; return new Node() { key = key, val = val, dat = val, lazy = ei, cnt = 1 }; } if (ope) Eval(n); if (c(key, n.key) < 0) n.left = Add(n.left, key, val); else n.right = Add(n.right, key, val); if (ope) n.needRecalc = true; n.cnt++; return Balance(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Balance(Node n) { if (!isNeedFix) return n; if (!IsBlack(n)) return n; if (IsRed(n.left) && IsRed(n.left.left)) { n = RotateR(n); n.left.isBlack = true; } else if (IsRed(n.left) && IsRed(n.left.right)) { n = RotateLR(n); n.left.isBlack = true; } else if (IsRed(n.right) && IsRed(n.right.left)) { n = RotateRL(n); n.right.isBlack = true; } else if (IsRed(n.right) && IsRed(n.right.right)) { n = RotateL(n); n.right.isBlack = true; } else isNeedFix = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(Key key) { root = Remove(root, key); if (root != null) root.isBlack = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Remove(Node n, Key key) { if (n == null) throw new Exception(); if (ope) Eval(n); n.cnt--; var r = c(key, n.key); if (r < 0) { n.left = Remove(n.left, key); if (ope) n.needRecalc = true; return BalanceL(n); } if (r > 0) { n.right = Remove(n.right, key); if (ope) n.needRecalc = true; return BalanceR(n); } if (n.left == null) { isNeedFix = n.isBlack; return n.right; } n.left = RemoveMax(n.left); n.key = lmax.key; n.val = lmax.val; if (ope) n.needRecalc = true; return BalanceL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RemoveMax(Node n) { if (ope) Eval(n); n.cnt--; if (n.right != null) { n.right = RemoveMax(n.right); if (ope) n.needRecalc = true; return BalanceR(n); } lmax = n; isNeedFix = n.isBlack; return n.left; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BalanceL(Node n) { if (!isNeedFix) return n; if (IsBlack(n.right) && IsRed(n.right.left)) { var b = n.isBlack; n = RotateRL(n); n.isBlack = b; n.left.isBlack = true; isNeedFix = false; } else if (IsBlack(n.right) && IsRed(n.right.right)) { var b = n.isBlack; n = RotateL(n); n.isBlack = b; n.right.isBlack = true; n.left.isBlack = true; isNeedFix = false; } else if (IsBlack(n.right)) { isNeedFix = n.isBlack; n.isBlack = true; n.right.isBlack = false; } else { n = RotateL(n); n.isBlack = true; n.left.isBlack = false; n.left = BalanceL(n.left); isNeedFix = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BalanceR(Node n) { if (!isNeedFix) return n; if (IsBlack(n.left) && IsRed(n.left.right)) { var b = n.isBlack; n = RotateLR(n); n.isBlack = b; n.right.isBlack = true; isNeedFix = false; } else if (IsBlack(n.left) && IsRed(n.left.left)) { var b = n.isBlack; n = RotateR(n); n.isBlack = b; n.left.isBlack = true; n.right.isBlack = true; isNeedFix = false; } else if (IsBlack(n.left)) { isNeedFix = n.isBlack; n.isBlack = true; n.left.isBlack = false; } else { n = RotateR(n); n.isBlack = true; n.right.isBlack = false; n.right = BalanceR(n.right); isNeedFix = false; } return n; } public KeyValuePair<Key, ValueT> this[long i] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return At(root, i); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] KeyValuePair<Key, ValueT> At(Node n, long i) { if (ope) Eval(n); if (n.left == null) { if (i == 0) return new KeyValuePair<Key, ValueT>(n.key, n.val); else return At(n.right, i - 1); } if (n.left.cnt == i) return new KeyValuePair<Key, ValueT>(n.key, n.val); if (n.left.cnt > i) return At(n.left, i); return At(n.right, i - n.left.cnt - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(Key key) { var t = LowerBound(key); return t < Cnt(root) && c(At(root, t).Key, key) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long UpperBound(Key key) => UpperBound(root, key); [MethodImpl(MethodImplOptions.AggressiveInlining)] long UpperBound(Node n, Key key) { if (n == null) return 0; var r = c(key, n.key); if (r < 0) return UpperBound(n.left, key); return Cnt(n.left) + 1 + UpperBound(n.right, key); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LowerBound(Key key) => LowerBound(root, key); [MethodImpl(MethodImplOptions.AggressiveInlining)] long LowerBound(Node n, Key key) { if (n == null) return 0; var r = c(key, n.key); if (r <= 0) return LowerBound(n.left, key); return Cnt(n.left) + 1 + LowerBound(n.right, key); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, ValueT> Min() { Node n = root.left, p = root; while (n != null) { p = n; if (ope) Eval(p); n = n.left; } return new KeyValuePair<Key, ValueT>(p.key, p.val); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, ValueT> Max() { Node n = root.right, p = root; while (n != null) { p = n; if (ope) Eval(p); n = n.right; } return new KeyValuePair<Key, ValueT>(p.key, p.val); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long l, long r, ValueE val) => Update(root, l, r, val); [MethodImpl(MethodImplOptions.AggressiveInlining)] void Update(Node n, long l, long r, ValueE val) { if (n == null) return; Eval(n); n.needRecalc = true; var lc = Cnt(n.left); if (lc < l) Update(n.right, l - lc - 1, r - lc - 1, val); else if (r <= lc) Update(n.left, l, r, val); else if (l <= 0 && Cnt(n) <= r) n.lazy = val; else { n.val = g(n.val, val); if (l < lc) Update(n.left, l, lc, val); if (lc + 1 < r) Update(n.right, 0, r - lc - 1, val); } return; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueT Query(long l, long r) => Query(root, l, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] ValueT Query(Node n, long l, long r) { var v1 = ti; var v2 = ti; var v3 = ti; if (n == null) return ti; Eval(n); var lc = Cnt(n.left); if (lc < l) v3 = Query(n.right, l - lc - 1, r - lc - 1); else if (r <= lc) v1 = Query(n.left, l, r); else if (l <= 0 && Cnt(n) <= r) { Recalc(n); v2 = n.dat; } else { if (l < lc) v1 = Query(n.left, l, lc); if (lc + 1 < r) v3 = Query(n.right, 0, r - lc - 1); v2 = n.val; } return f(f(v1, v2), v3); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => root != null; public long Count => Cnt(root); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<KeyValuePair<Key, ValueT>> List() => L(root); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<KeyValuePair<Key, ValueT>> L(Node n) { if (n == null) yield break; foreach (var i in L(n.left)) yield return i; yield return new KeyValuePair<Key, ValueT>(n.key, n.val); foreach (var i in L(n.right)) yield return i; } } class LIB_RedBlackTree<Key, Value> { LIB_RedBlackTree<Key, Value, Value> tree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(Comparison<Key> c) { tree = new LIB_RedBlackTree<Key, Value, Value>( default(Value), default(Value), (x, y) => x, (x, y) => x, (x, y) => x, c, false); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree() : this(Comparer<Key>.Default.Compare) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(Key key, Value val) => tree.Add(key, val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(Key key) => tree.Remove(key); public KeyValuePair<Key, Value> this[long i] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return tree[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(Key key) => tree.Have(key); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long UpperBound(Key key) => tree.UpperBound(key); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LowerBound(Key key) => tree.LowerBound(key); [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, Value> Min() => tree.Min(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public KeyValuePair<Key, Value> Max() => tree.Max(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => tree.Any(); public long Count => tree.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<KeyValuePair<Key, Value>> List() => tree.List(); } class LIB_RedBlackTree<T> { LIB_RedBlackTree<T, T, T> tree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree(Comparison<T> c) { tree = new LIB_RedBlackTree<T, T, T>(default(T), default(T), (x, y) => x, (x, y) => x, (x, y) => x, c, false); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_RedBlackTree() : this(Comparer<T>.Default.Compare) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T val) => tree.Add(val, val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T val) => tree.Remove(val); public T this[long i] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return tree[i].Key; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T val) => tree.Have(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long UpperBound(T val) => tree.UpperBound(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LowerBound(T val) => tree.LowerBound(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() => tree.Min().Key; [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() => tree.Max().Key; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => tree.Any(); public long Count => tree.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => tree.List().Select(e => e.Key); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
5,209
2
using System; using System.Linq; using System.Collections.Generic; public static class Program { public static void Main() { long[] nda = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = nda[0]; long d = nda[1]; long a = nda[2]; var data = new List<Tuple<long, long>>(); for (int i = 0; i < n; i++) { long[] xh = Console.ReadLine().Split().Select(long.Parse).ToArray(); data.Add(new Tuple<long, long>(xh[0], (xh[1] + a - 1) / a)); } data.Sort(); long ans = 0; long now = 0; long[] lazy = new long[n + 1]; int j = 0; for (int i = 0; i < n; i++) { long x = data[i].Item1; long h = data[i].Item2; now -= lazy[i]; h = Math.Max(0, h - now); ans += h; now += h; while (j < n && data[j].Item1 <= x + 2 * d + 1) j++; lazy[j] += h; } Console.WriteLine(ans); } } /* まず、爆弾は固定ダメージですから、HP をすべて A で割っておくことで、A = 1 としてよいです。 敵を座標でソートして、敵を左から順に、なるべく右に爆弾を置いて倒します。 このとき巻き添えになる敵がたくさんいたら間に合いませんから、それは隣接差で遅延評価しましょう。 配列を用意して、それの累積和が与えたダメージになるようにしておきましょう。 ただし、累積和をとってはいけません。せっかく順番に動いていますから、現在の累積和を管理しておきましょう。 */
using System; using System.Linq; using System.Collections.Generic; public static class Program { public static void Main() { long[] nda = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = nda[0]; long d = nda[1]; long a = nda[2]; var data = new List<Tuple<long, long>>(); for (int i = 0; i < n; i++) { long[] xh = Console.ReadLine().Split().Select(long.Parse).ToArray(); data.Add(new Tuple<long, long>(xh[0], (xh[1] + a - 1) / a)); } data.Sort(); long ans = 0; long now = 0; long[] lazy = new long[n + 1]; int j = 0; for (int i = 0; i < n; i++) { long x = data[i].Item1; long h = data[i].Item2; now -= lazy[i]; h = Math.Max(0, h - now); ans += h; now += h; while (j < n && data[j].Item1 <= x + 2 * d) j++; lazy[j] += h; } Console.WriteLine(ans); } } /* まず、爆弾は固定ダメージですから、HP をすべて A で割っておくことで、A = 1 としてよいです。 敵を座標でソートして、敵を左から順に、なるべく右に爆弾を置いて倒します。 このとき巻き添えになる敵がたくさんいたら間に合いませんから、それは隣接差で遅延評価しましょう。 配列を用意して、それの累積和が与えたダメージになるようにしておきましょう。 ただし、累積和をとってはいけません。せっかく順番に動いていますから、現在の累積和を管理しておきましょう。 */
[["-", 0, 52, 15, 16, 12, 16, 12, 16, 17, 72], ["-", 0, 52, 15, 16, 12, 16, 12, 16, 12, 203]]
8
306
2
using System; using System.Linq; using System.Collections.Generic; public static class Program { public static void Main() { long[] nda = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = nda[0]; long d = nda[1]; long a = nda[2]; var data = new List<Tuple<long, long>>(); for (int i = 0; i < n; i++) { long[] xh = Console.ReadLine().Split().Select(long.Parse).ToArray(); data.Add(new Tuple<long, long>(xh[0], xh[1] / a)); } data.Sort(); long ans = 0; long now = 0; long[] lazy = new long[n + 1]; for (int i = 0; i < n; i++) { long x = data[i].Item1; long h = data[i].Item2; now -= lazy[i]; h = Math.Max(0, h - now); ans += h; now += h; int lwr = -1; int upr = (int)n; while (1 < upr - lwr) { int mid = (upr + lwr) / 2; if (data[mid].Item1 <= x + 2 * d) lwr = mid; else upr = mid; } lazy[upr] += h; } Console.WriteLine(ans); } } /* まず、爆弾は固定ダメージですから、HP をすべて A で割っておくことで、A = 1 としてよいです。 敵を座標でソートして、敵を左から順に、なるべく右に爆弾を置いて倒します。 このとき巻き添えになる敵がたくさんいたら間に合いませんから、それは隣接差で遅延評価しましょう。 配列を用意して、それの累積和が与えたダメージになるようにしておきましょう。 ただし、累積和をとってはいけません。せっかく順番に動いていますから、現在の累積和を管理しておきましょう。 */
using System; using System.Linq; using System.Collections.Generic; public static class Program { public static void Main() { long[] nda = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = nda[0]; long d = nda[1]; long a = nda[2]; var data = new List<Tuple<long, long>>(); for (int i = 0; i < n; i++) { long[] xh = Console.ReadLine().Split().Select(long.Parse).ToArray(); data.Add(new Tuple<long, long>(xh[0], (xh[1] + a - 1) / a)); } data.Sort(); long ans = 0; long now = 0; long[] lazy = new long[n + 1]; for (int i = 0; i < n; i++) { long x = data[i].Item1; long h = data[i].Item2; now -= lazy[i]; h = Math.Max(0, h - now); ans += h; now += h; int lwr = -1; int upr = (int)n; while (1 < upr - lwr) { int mid = (upr + lwr) / 2; if (data[mid].Item1 <= x + 2 * d) lwr = mid; else upr = mid; } lazy[upr] += h; } Console.WriteLine(ans); } } /* まず、爆弾は固定ダメージですから、HP をすべて A で割っておくことで、A = 1 としてよいです。 敵を座標でソートして、敵を左から順に、なるべく右に爆弾を置いて倒します。 このとき巻き添えになる敵がたくさんいたら間に合いませんから、それは隣接差で遅延評価しましょう。 配列を用意して、それの累積和が与えたダメージになるようにしておきましょう。 ただし、累積和をとってはいけません。せっかく順番に動いていますから、現在の累積和を管理しておきましょう。 */
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
330
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoders { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var N = inputArray[0]; var K = inputArray[1]; //答えの出力 var ans = N == K ? "AC" : "WA"; Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// ある整数の先頭の桁を取得する /// </summary> /// <returns></returns> private static int getInitial(long n) { while (n >= 10) { n = n / 10; } return (int)n; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoders { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var N = inputArray[0]; var K = inputArray[1]; //答えの出力 var ans = N == K ? "Yes" : "No"; Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// ある整数の先頭の桁を取得する /// </summary> /// <returns></returns> private static int getInitial(long n) { while (n >= 10) { n = n / 10; } return (int)n; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
240
4
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(); int N, M; Int32.TryParse(a[0], out N); Int32.TryParse(a[1], out M); string a2 = (N == M) ? "YES" : "NO"; Console.WriteLine(a2); } } }
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(); int N, M; Int32.TryParse(a[0], out N); Int32.TryParse(a[1], out M); string a2 = (N == M) ? "Yes" : "No"; Console.WriteLine(a2); } } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
97
4
using System; class ACorWA { static void Main(string[] args) { string[] line = System.Console.ReadLine().Trim().Split('\t'); if (line[0] == line[1]) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } }
using System; class ACorWA { static void Main(string[] args) { string[] line = System.Console.ReadLine().Trim().Split(' '); if (line[0] == line[1]) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 44], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
81
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC152A { class Program { static void Main(string[] args) { int N, M; var word = Console.ReadLine().Split(' '); M = int.Parse(word[0]); N = int.Parse(word[1]); if (N == M) Console.Write("YES"); else Console.Write("NO"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC152A { class Program { static void Main(string[] args) { int N, M; var word = Console.ReadLine().Split(' '); M = int.Parse(word[0]); N = int.Parse(word[1]); if (N == M) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["-", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22]]
8
122
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { int a, b; string[] str = Console.ReadLine().Split(' '); a = int.Parse(str[0]); b = int.Parse(str[1]); if (a == b) Console.WriteLine("AC"); else Console.WriteLine("WC"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { int a, b; string[] str = Console.ReadLine().Split(' '); a = int.Parse(str[0]); b = int.Parse(str[1]); if (a == b) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
118
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var num = cin.ReadInt; var solved = cin.ReadInt; if (num == solved) WriteLine("yes"); else WriteLine("no"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var num = cin.ReadInt; var solved = cin.ReadInt; if (num == solved) WriteLine("Yes"); else WriteLine("No"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
460
4
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var input = IntInput(' '); if (input[0] == input[1]) Output("YES"); else Output("No"); } #region ReadLineメソッド /// <summary> /// 文字列をリストで返す /// </summary> static List<string> StringInput(char splitChar) { return Console.ReadLine().Split(splitChar).ToList(); } /// <summary> /// 文字列を分割し、数字のリストで返す /// </summary> static List<int> IntInput(char splitChar) { return StringInput(splitChar).Select(str => int.Parse(str)).ToList(); } /// <summary> /// 数字を1つ返す /// </summary> static int IntInput() { return int.Parse(Console.ReadLine()); } #endregion #region WriteLineメソッド /// <summary> /// string型を改行せずに出力する /// </summary> static void Output(string str) { Console.Write(str); } /// <summary> /// int型をそのまま出力する /// </summary> static void Output(int number) { Console.WriteLine(number); } /// <summary> /// int型のリストを改行して出力する /// </summary> static void Output(List<int> numList) { numList.ForEach(num => Console.WriteLine(num)); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var input = IntInput(' '); if (input[0] == input[1]) { Output("Yes"); } else { Output("No"); } } #region ReadLineメソッド /// <summary> /// 文字列をリストで返す /// </summary> static List<string> StringInput(char splitChar) { return Console.ReadLine().Split(splitChar).ToList(); } /// <summary> /// 文字列を分割し、数字のリストで返す /// </summary> static List<int> IntInput(char splitChar) { return StringInput(splitChar).Select(str => int.Parse(str)).ToList(); } /// <summary> /// 数字を1つ返す /// </summary> static int IntInput() { return int.Parse(Console.ReadLine()); } #endregion #region WriteLineメソッド /// <summary> /// string型を改行せずに出力する /// </summary> static void Output(string str) { Console.Write(str); } /// <summary> /// int型をそのまま出力する /// </summary> static void Output(int number) { Console.WriteLine(number); } /// <summary> /// int型のリストを改行して出力する /// </summary> static void Output(List<int> numList) { numList.ForEach(num => Console.WriteLine(num)); } #endregion } }
[["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
238
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc141/tasks/abc152_a public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long n = inputLongArray[0]; long m = inputLongArray[1]; string result = n == m ? "yes" : "no"; Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc141/tasks/abc152_a public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long n = inputLongArray[0]; long m = inputLongArray[1]; string result = n == m ? "Yes" : "No"; Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
159
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0027 { class Program { static void Main(string[] args) { var str = Console.ReadLine(); int a = int.Parse(str.Split(' ')[0]); int b = int.Parse(str.Split(' ')[1]); string astr = ""; string bstr = ""; for (int i = 0; i < a; i++) { astr += b.ToString(); } for (int i = 0; i < a; i++) { bstr += a.ToString(); } if (astr.CompareTo(bstr) < 0) { Console.WriteLine(astr); } else { Console.WriteLine(bstr); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0027 { class Program { static void Main(string[] args) { var str = Console.ReadLine(); int a = int.Parse(str.Split(' ')[0]); int b = int.Parse(str.Split(' ')[1]); string astr = ""; string bstr = ""; for (int i = 0; i < a; i++) { astr += b.ToString(); } for (int i = 0; i < b; i++) { bstr += a.ToString(); } if (astr.CompareTo(bstr) < 0) { Console.WriteLine(astr); } else { Console.WriteLine(bstr); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
185
2
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(); int N, M; Int32.TryParse(a[0], out N); Int32.TryParse(a[1], out M); var a2 = (N <= M) ? N : M; string ans = ""; for (int i = 0; i < a2; i++) { ans += a2.ToString(); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(); int N, M; Int32.TryParse(a[0], out N); Int32.TryParse(a[1], out M); var a2 = (N <= M) ? N : M; string ans = ""; for (int i = 0; i < (M + N - a2); i++) { ans += a2.ToString(); } Console.WriteLine(ans); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 25]]
8
123
6
using System; using System.Linq; using System.Collections.Generic; using System.IO; class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var a = input[0]; var b = input[1]; if (a >= b) { for (int i = 0; i < a; i++) Console.Write(b); } else { for (int i = 0; i < b; i++) Console.WriteLine(a); } Console.Out.Flush(); } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var a = input[0]; var b = input[1]; if (a >= b) { for (int i = 0; i < a; i++) Console.Write(b); } else { for (int i = 0; i < b; i++) Console.Write(a); } Console.Out.Flush(); } }
[["-", 0, 7, 8, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 7, 8, 1, 0, 213, 63, 214, 141, 22]]
8
193
2
using System; using System.Linq; using System.Collections.Generic; namespace abc152b { class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); if (inp[0] > inp[1]) { foreach (var a in Enumerable.Repeat(inp[0], inp[1]).ToList()) { Console.Write(a); } } else if (inp[1] > inp[0]) { foreach (var a in Enumerable.Repeat(inp[1], inp[0]).ToList()) { Console.Write(a); } } else { foreach (var a in Enumerable.Repeat(inp[0], inp[0]).ToList()) { Console.Write(a); } } } } }
using System; using System.Linq; using System.Collections.Generic; namespace abc152b { class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); if (inp[0] > inp[1]) { foreach (var a in Enumerable.Repeat(inp[1], inp[0]).ToList()) { Console.Write(a); } } else if (inp[1] > inp[0]) { foreach (var a in Enumerable.Repeat(inp[0], inp[1]).ToList()) { Console.Write(a); } } else { foreach (var a in Enumerable.Repeat(inp[0], inp[0]).ToList()) { Console.Write(a); } } } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
194
8
using System; class sample { static void Main() { string[] input = Console.ReadLine().Split(' '); int[] inputnum = new int[2]; string input0 = ""; string input1 = ""; inputnum[0] = Convert.ToInt32(input[0]); inputnum[1] = Convert.ToInt32(input[1]); for (int i = 0; i < inputnum[0]; i++) { input1 += input[1]; } for (int i = 0; i < inputnum[1]; i++) { input0 += input[0]; } if (input0.CompareTo(input1) <= 0) { Console.WriteLine(input1); } else { Console.WriteLine(input0); } } }
using System; class sample { static void Main() { string[] input = Console.ReadLine().Split(' '); int[] inputnum = new int[2]; string input0 = ""; string input1 = ""; inputnum[0] = Convert.ToInt32(input[0]); inputnum[1] = Convert.ToInt32(input[1]); for (int i = 0; i < inputnum[0]; i++) { input1 += input[1]; } for (int i = 0; i < inputnum[1]; i++) { input0 += input[0]; } if (input0.CompareTo(input1) <= 0) { Console.WriteLine(input0); } else { Console.WriteLine(input1); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
167
4
using System; using System.Collections.Generic; namespace ATCoder { class Program { static void Main(string[] args) { var list = new List<string>(); var input = Console.ReadLine(); string[] token = input.Split(' '); string a = token[0]; string b = token[1]; string str_a = ConvertStr(a, int.Parse(b)); string str_b = ConvertStr(b, int.Parse(a)); list.Add(str_a); list.Add(str_b); list.Sort(); Console.WriteLine(list[0]); } static string ConvertStr(string str, int num) { string ret = ""; for (int i = 0; i > num; i++) { ret += str; } return ret; } } }
using System; using System.Collections.Generic; namespace ATCoder { class Program { static void Main(string[] args) { var list = new List<string>(); var input = Console.ReadLine(); string[] token = input.Split(' '); string a = token[0]; string b = token[1]; string str_a = ConvertStr(a, int.Parse(b)); string str_b = ConvertStr(b, int.Parse(a)); list.Add(str_a); list.Add(str_b); list.Sort(); Console.WriteLine(list[0]); } static string ConvertStr(string str, int num) { string ret = ""; for (int i = 0; i < num; i++) { ret += str; } return ret; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
180
2
using System; using System.Linq; namespace AtCoder_Begginer_Contest1 { class Program { static void Main(string[] args) { string[] ab = Console.ReadLine().Split(); int a = int.Parse(ab[0]); int b = int.Parse(ab[1]); if (a > b) { b = a; ab[0] = ab[1]; } string ans = ab[1]; for (int i = 0; i < b - 1; i++) { ans += ab[0]; } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace AtCoder_Begginer_Contest1 { class Program { static void Main(string[] args) { string[] ab = Console.ReadLine().Split(); int a = int.Parse(ab[0]); int b = int.Parse(ab[1]); if (a > b) { b = a; ab[0] = ab[1]; } string ans = ab[0]; for (int i = 0; i < b - 1; i++) { ans += ab[0]; } Console.WriteLine(ans); } } }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
8
130
2
using System; using System.Collections.Generic; using System.Linq; static class MainClass { public static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var list = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); var ans = new List<long>(); var c = 0; var min = list.Max(); for (var i = 0; i < N; i++) { if (min > list[i]) { min = list[i]; c++; } } Console.WriteLine(c); } static long ModPow(long a, long n, long p) { if (n == 1) return a % p; if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p; var t = ModPow(a, n / 2, p); return (t * t) % p; } static long Combination(long n, long a) { var ary1 = Enumerable.Range((int)n - (int)a + 1, (int)a); var ary2 = Enumerable.Range(1, (int)a); return ary1.Aggregate((e, next) => e * next) / ary2.Aggregate((e, next) => e * next); } }
using System; using System.Collections.Generic; using System.Linq; static class MainClass { public static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var list = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); var ans = new List<long>(); var c = 0; var min = list.Max() + 1; for (var i = 0; i < N; i++) { if (min > list[i]) { min = list[i]; c++; } } Console.WriteLine(c); } static long ModPow(long a, long n, long p) { if (n == 1) return a % p; if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p; var t = ModPow(a, n / 2, p); return (t * t) % p; } static long Combination(long n, long a) { var ary1 = Enumerable.Range((int)n - (int)a + 1, (int)a); var ary2 = Enumerable.Range(1, (int)a); return ary1.Aggregate((e, next) => e * next) / ary2.Aggregate((e, next) => e * next); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
300
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC152C { class Program { static void Main(string[] args) { int N, min, a; a = 0; N = int.Parse(Console.ReadLine()); min = N; int[] P = new int[N]; var word = Console.ReadLine().Split(' '); for (int i = 0; i <= N - 1; i++) { P[i] = int.Parse(word[i]); if (P[i] < min) { min = P[i]; a++; } } Console.WriteLine(a); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC152C { class Program { static void Main(string[] args) { int N, min, a; a = 0; N = int.Parse(Console.ReadLine()); min = N + 1; int[] P = new int[N]; var word = Console.ReadLine().Split(' '); for (int i = 0; i <= N - 1; i++) { P[i] = int.Parse(word[i]); if (P[i] < min) { min = P[i]; a++; } } Console.WriteLine(a); Console.ReadKey(); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
168
2
using System; using System.Linq; namespace C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(int.Parse).ToList(); var count = 0; var min = int.MaxValue; foreach (var x in p) { if (min < x) { min = x; count++; } } Console.WriteLine(count); } } }
using System; using System.Linq; namespace C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(int.Parse).ToList(); var count = 0; var min = int.MaxValue; foreach (var x in p) { if (min > x) { min = x; count++; } } Console.WriteLine(count); } } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47]]
8
108
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; public class Program { static public void Main(string[] args) { string str = Console.ReadLine(); int[] data = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int num = 0; int max = data[0]; for (int i = 0; i < data.Length; i++) { if (data[i] <= max) { num++; } max = Math.Max(max, data[i]); } Console.WriteLine(num); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; public class Program { static public void Main(string[] args) { string str = Console.ReadLine(); int[] data = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int num = 0; int min = data[0]; for (int i = 0; i < data.Length; i++) { if (data[i] <= min) { num++; } min = Math.Min(min, data[i]); } Console.WriteLine(num); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
146
10
using System; namespace tst { class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); string[] In = Console.ReadLine().Split(' '); int[] P = new int[n]; for (int i = 0; i < n; i++) { P[i] = int.Parse(In[i]); } int cnt = 0; if (n == 1) { cnt++; } else { int min = 100000000; for (int i = 0; i < n - 1; i++) { if (P[i] <= min) { min = P[i]; cnt++; } } } Console.WriteLine(cnt); } } }
using System; namespace tst { class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); string[] In = Console.ReadLine().Split(' '); int[] P = new int[n]; for (int i = 0; i < n; i++) { P[i] = int.Parse(In[i]); } int cnt = 0; if (n == 1) { cnt++; } else { int min = 100000000; for (int i = 0; i < n; i++) { if (P[i] <= min) { min = P[i]; cnt++; } } } Console.WriteLine(cnt); } } }
[["-", 75, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 75, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
163
2