結果
| 問題 |
No.3313 Matryoshka
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-24 22:45:19 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,708 bytes |
| コンパイル時間 | 7,949 ms |
| コンパイル使用メモリ | 167,664 KB |
| 実行使用メモリ | 194,496 KB |
| 最終ジャッジ日時 | 2025-10-24 22:45:56 |
| 合計ジャッジ時間 | 29,677 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 4 WA * 31 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (109 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
static long[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => long.Parse(ReadLine())).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var n = NN;
var map = NArr(n);
var ans = 0L;
Array.Sort(map, (l, r) => l[0].CompareTo(r[0]));
var ft = new FenwickTree(1_000_001);
for (var i = 0; i < n; ++i) ft.Add(map[i][1], 1);
for (var i = 0; i < n; ++i)
{
ans += ft.Sum(map[i][1] - 1) - ft.Sum(map[i][0]);
ft.Add(map[i][1], -1);
}
WriteLine(ans);
}
class FenwickTree
{
int size;
long[] tree;
public FenwickTree(int size)
{
this.size = size;
tree = new long[size + 2];
}
public void Add(int index, int value)
{
++index;
for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
}
/// <summary>先頭からindexまでの和(include index)</summary>
public long Sum(int index)
{
if (index < 0) return 0;
++index;
var sum = 0L;
for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
return sum;
}
public long Get(int index)
{
if (index == 0) return Sum(0);
return Sum(index) - Sum(index - 1);
}
/// <summary>Sum(x) >= value となる最小のxを求める</summary>
// 各要素は非負であること
public int LowerBound(long value)
{
if (value < 0) return -1;
var x = 0;
var b = 1;
while (b * 2 <= size) b <<= 1;
for (var k = b; k > 0; k >>= 1)
{
if (x + k <= size && tree[x + k] < value)
{
value -= tree[x + k];
x += k;
}
}
return x;
}
}
}