SDNU_ACM_ICPC_2020_Winter_Practice_1st

SDNU_ACM_ICPC_2020_Winter_Practice_1st

E - E CodeForces - 705B

Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.

Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).

Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?

Peter is pretty good at math, but now he asks you to help.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.

The second line contains n space separated integers a1, a2, …, an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.

Output
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.

Examples
Input
3
1 2 3
Output
2
1
1
Input
5
1 1 5 1 1
Output
2
2
2
2
2
Note
In the first sample test:

In Peter’s first test, there’s only one cycle with 1 vertex. First player cannot make a move and loses.

In his second test, there’s one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can’t make any move and loses.

In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size 1 and one with size 2. Now cycles have 1, 1, 2, 2 vertices. Second player’s only move is to replace a cycle of size 2 with 2 cycles of size 1. And cycles are 1, 1, 1, 1, 2. First player replaces the last cycle with 2 cycles with size 1 and wins.

In the second sample test:

Having cycles of size 1 is like not having them (because no one can make a move on them).

In Peter’s third test: There a cycle of size 5 (others don’t matter). First player has two options: replace it with cycles of sizes 1 and 4 or 2 and 3.

  • If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player’s only option to replace one of them with two cycles of size 1. Second player does the same thing with the other cycle. First player can’t make any move and loses.
  • If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes 1 and 2. Now only cycles with more than one vertex are two cycles of size 2. As shown in previous case, with 2 cycles of size 2 second player wins.

So, either way first player loses.

题解

对于一个石子堆,它的数量不变,那么拆解方式也是不变的,那么只需要判断一下总和的奇偶就阔以了

#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
const double pi = acos(-1.0);
const double eps = 1e-12;
const int MAXN = 1e7 + 10;
const int inf = __LONG_MAX__;
const int enf = LONG_MIN;
const long long INF = LLONG_MAX;
const long long ENF = LLONG_MIN;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n;i++){
        int x;
        cin >> x;
        sum += x-1;
        if(sum%2==0)
            cout << 2 << endl;
        else
            cout << 1 << endl;
    }
        return 0;
}

I - I HDU - 6638

There are n pirate chests buried in Byteland, labeled by 1,2,…,n. The i-th chest’s location is (xi,yi), and its value is wi, wi can be negative since the pirate can add some poisonous gases into the chest. When you open the i-th pirate chest, you will get wi value.

You want to make money from these pirate chests. You can select a rectangle, the sides of which are all paralleled to the axes, and then all the chests inside it or on its border will be opened. Note that you must open all the chests within that range regardless of their values are positive or negative. But you can choose a rectangle with nothing in it to get a zero sum.

Please write a program to find the best rectangle with maximum total value.
Input
The first line of the input contains an integer T(1≤T≤100), denoting the number of test cases.

In each test case, there is one integer n(1≤n≤2000) in the first line, denoting the number of pirate chests.

For the next n lines, each line contains three integers xi,yi,wi(−109≤xi,yi,wi≤109), denoting each pirate chest.

It is guaranteed that ∑n≤10000.
Output
For each test case, print a single line containing an integer, denoting the maximum total value.
Sample Input
2
4
1 1 50
2 1 50
1 2 50
2 2 -500
2
-1 1 5
-1 1 1
Sample Output
100
6

题解

这个题用到了维护最大子段和的线段树
我们需要对其进行降维
考虑矩形,我们确定一个上下边界后,按照另一维度建立线段树,列如以 y y y作为上下边界,那么只需要将其中的 y i y_i yi对应的点加进去就阔以了.
线段树维护 x x x轴, x i x_i xi上面对应所有点在 y y y确定的所有点的和.
离散化,降维,都是线段树的经典操作.

#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
const double pi = acos(-1.0);
const double eps = 1e-12;
typedef long long ll;
const ll INF = LLONG_MAX;
const ll ENF = LLONG_MIN;
const int MAXN = 1e7 + 10;
const int inf = __LONG_MAX__;
const int enf = LONG_MIN;

#define ls(p) (p << 1)
#define rs(p) (p << 1 | 1)
struct node {
    ll d;
    ll pre_sum, post_sum, sum;
    node operator+(const node p) const
    {
        node ip;
        ip.d = d + p.d;
        ip.sum = max(0LL, max(sum, p.sum));
        ip.sum = max(ip.sum, max(0LL, post_sum) + max(0LL, p.pre_sum));
        ip.pre_sum = max(0LL, max(pre_sum, d + p.pre_sum));
        ip.post_sum = max(0LL, max(p.post_sum, post_sum + p.d));
        return ip;
    }
} tree[MAXN << 2];
void up(int p)
{
    tree[p] = tree[ls(p)] + tree[rs(p)];
}
void built(int p, int l, int r)
{
    tree[p].d = tree[p].post_sum = tree[p].pre_sum = tree[p].sum = 0;
    if (l == r)
        return;
    else {
        int mid = (l + r) >> 1;
        built(ls(p), l, mid);
        built(rs(p), mid + 1, r);
    }
}
void update(int p, int l, int r, int pos, int k)
{
    if (l == r && l == pos) {
        tree[p].d += k;
        tree[p].post_sum += k;
        tree[p].pre_sum += k;
        tree[p].sum += k;
    } else {
        int mid = (l + r) >> 1;
        pos <= mid ? update(ls(p), l, mid, pos, k) : update(rs(p), mid + 1, r, pos, k);
        up(p);
    }
}
struct vec {
    int x, y, w;
    bool operator<(vec b)
    {
        return (y == b.y ? x < b.x : y < b.y);
    }
    friend istream& operator>>(istream& in, vec& a)
    {
        scanf("%d%d%d", &a.x, &a.y, &a.w);
        return in;
    }
} p[MAXN];
int v[MAXN];
int main()
{
    int n, t;
    cin >> t;
    while (t--) {
        cin >> n;
        int lenx = 0, leny = 0;
        for (int i = 1; i <= n; i++) {
            cin >> p[i];
            v[++lenx] = p[i].x;
        }
        sort(v + 1, v + lenx + 1);
        lenx = unique(v + 1, v + lenx + 1) - v - 1;
        for (int i = 1; i <= n; i++)
            p[i].x = lower_bound(v + 1, v + lenx + 1, p[i].x) - v;

        for (int i = 1; i <= n; i++)
            v[++leny] = p[i].y;
        sort(v + 1, v + leny + 1);
        leny = unique(v + 1, v + leny + 1) - v - 1;
        for (int i = 1; i <= n; i++)
            p[i].y = lower_bound(v + 1, v + leny + 1, p[i].y) - v;

        sort(p + 1, p + n + 1);
        ll ans = 0;
        int pos = 0;
        for (int i = 1; i <= leny; i++) {
            for (int j = n; j >= 1; j--) //枚举上边界,可以二分
                if (p[j].y <= i) {
                    pos = j;
                    break;
                }
            int root = 1;
            built(root, 1, lenx);
            for (int j = i; j >= 1; j--) { //枚举下边界
                while (pos && p[pos].y >= j) {
                    update(root, 1, lenx, p[pos].x, p[pos].w);
                    pos--;
                }
                ans = max(ans, tree[root].sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值