提出 #10169734


ソースコード 拡げる

#include <bits/stdc++.h>
#define Mid ((L + R) >> 1)
#define Left (Node << 1)
#define Right (Node << 1 | 1)

using namespace std;

typedef pair <int,int> pii;

const int N = 200200;
const int M = 4 * N;
const int Inf = 2e9;

int n, m;
int A[N];
pii a[N];
set <pii> Have[N];
vector <pii> Cur[N];

int Tree[M];
int Lazy[M];

void Merge(int Node)
{
    Tree[Node] = Tree[Left] ^ Tree[Right];
}

void PushLazy(int Node, int Len)
{
    if(Lazy[Node])
    {
        Tree[Node] ^= Lazy[Node];

        if(Len > 1)
        {
            Lazy[Left] ^= Lazy[Node];
            Lazy[Right] ^= Lazy[Node];
        }

        Lazy[Node] = 0;
    }
}

void Build(int Node = 1, int L = 0, int R = n - 1)
{
    Tree[Node] = Lazy[Node] = 0;

    if(L == R)  return void(Tree[Node] = A[L]);

    Build(Left, L, Mid);
    Build(Right, Mid + 1, R);

    Merge(Node);
}

void Update(int i, int j, int x, int Node = 1, int L = 0, int R = n - 1)
{
    PushLazy(Node, R - L + 1);

    if(i > j || L > R)  return ;
    if(j < L || R < i)  return ;

    if(i <= L && R <= j)
    {
        Lazy[Node] ^= x;
        return PushLazy(Node, R - L + 1);
    }

    Update(i, j, x, Left, L, Mid);
    Update(i, j, x, Right, Mid + 1, R);

    Merge(Node);
}

int Query(int i, int j, int Node = 1, int L = 0, int R = n - 1)
{
    PushLazy(Node, R - L + 1);

    if(i > j || L > R)      return 0;
    if(j < L || R < i)      return 0;
    if(i <= L && R <= j)    return Tree[Node];

    return Query(i, j, Left, L, Mid) ^ Query(i, j, Right, Mid + 1, R);
}

int main()
{
    cin >> n >> m;

    for(int i = 0; i < n; i++)  scanf("%d%d", &a[i].first, &a[i].second);

    sort(a, a + n);

    for(int i = 0; i < n; i++)  A[i] = a[i].second;

    for(int i = 0; i < m; i++)
    {
        int L, R;   scanf("%d%d", &L, &R);

        L = lower_bound(a, a + n, pii(L, -Inf)) - a;
        R = upper_bound(a, a + n, pii(R, +Inf)) - 1 - a;

        if(L > R) continue;

        Have[L].insert(pii(R, i));
    }

    Build();

    vector <bool> Used(m, false);

    for(int i = 0; i < n; i++)
    {
        for(pii p : Have[i])    Cur[i].push_back(p);

        Have[i].clear();

        int Last = i;

        for(pii p : Cur[i])
        {
            if(Last <= p.first)
            {
                Have[Last].insert(pii(p.first, p.second));
                Last = p.first + 1;
            }
        }

        if(Query(i, i))
        {
            if(Have[i].empty()) return 0 * puts("-1");

            Update(i, (*Have[i].begin()).first, 1);

            Used[(*Have[i].begin()).second] = true;
        }
    }

    for(int i = n - 1; ~i; --i)
    {
        reverse(Cur[i].begin(), Cur[i].end());

        bool Last = false;

        for(pii p : Cur[i])
        {
            Used[p.second] = Last ^ Used[p.second];
            Last ^= Used[p.second];
        }

        reverse(Cur[i].begin(), Cur[i].end());
    }

    vector <int> Ans;

    for(int i = 0; i < m; i++)
        if(Used[i])
            Ans.push_back(i);

    cout << Ans.size() << endl;
    for(int x : Ans)    printf("%d ", x + 1);
    puts("");
}

提出情報

提出日時
問題 F - Perils in Parallel
ユーザ The_Last_Wizard
言語 C++14 (GCC 5.4.1)
得点 600
コード長 3237 Byte
結果 AC
実行時間 483 ms
メモリ 46716 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:90:73: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < n; i++)  scanf("%d%d", &a[i].first, &a[i].second);
                                                                         ^
./Main.cpp:98:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         int L, R;   scanf("%d%d", &L, &R);
                                          ^

ジャッジ結果

セット名 Sample Subtask1
得点 / 配点 0 / 0 600 / 600
結果
AC × 4
AC × 27
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 7 ms 18688 KiB
sample_02.txt AC 7 ms 18688 KiB
sample_03.txt AC 7 ms 18688 KiB
sample_04.txt AC 7 ms 18688 KiB
sub1_01.txt AC 193 ms 30464 KiB
sub1_02.txt AC 104 ms 24064 KiB
sub1_03.txt AC 47 ms 22016 KiB
sub1_04.txt AC 66 ms 23296 KiB
sub1_05.txt AC 27 ms 20352 KiB
sub1_06.txt AC 42 ms 21632 KiB
sub1_07.txt AC 82 ms 23552 KiB
sub1_08.txt AC 150 ms 28928 KiB
sub1_09.txt AC 102 ms 28928 KiB
sub1_10.txt AC 108 ms 28540 KiB
sub1_11.txt AC 21 ms 19968 KiB
sub1_12.txt AC 79 ms 24064 KiB
sub1_13.txt AC 128 ms 28544 KiB
sub1_14.txt AC 76 ms 23424 KiB
sub1_15.txt AC 80 ms 23680 KiB
sub1_16.txt AC 72 ms 23808 KiB
sub1_17.txt AC 14 ms 19328 KiB
sub1_18.txt AC 53 ms 21760 KiB
sub1_19.txt AC 41 ms 21504 KiB
sub1_20.txt AC 49 ms 21760 KiB
sub1_21.txt AC 483 ms 46716 KiB
sub1_22.txt AC 86 ms 23936 KiB
sub1_23.txt AC 15 ms 19456 KiB