QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620552#8527. Power DivisionsbadmintonWA 9ms22352kbC++143.2kb2024-10-07 19:10:482024-10-07 19:10:49

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 19:10:49]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:22352kb
  • [2024-10-07 19:10:48]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;

#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

template<class X, class Y>
    bool minz(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } return false;
    }
template<class X, class Y>
    bool maxz(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } return false;
    }

const int N = 1e6 + 50;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;

ll rd (ll l, ll r){
    ll res = 0;
    for (int i = 0; i < 4; i++)
        res = (res << 15) ^ rand();
    return res;
}


void add (ll &u, ll v){
    u += v;
    if (u >= mod)
        u -= mod;
}

ll a[N], n, cur, pre[N], pw[N];
ll dp[N], mn, mx;
map <int, int> bit;

void addbit (int x){
    cur ^= pw[x];
    bit[x]++;

    while (bit[x] > 1){
        bit[x] -= 2;

        if (mn == x)
            mn++;
        bit[++x]++;
        cur ^= pw[x]; 
    }

    maxz(mx, x);
}

void solve (int l, int r){
    if (l == r){
        add(dp[l], dp[l - 1]);
     //   cout <<l << " " << r << " " << dp[l] << " zz\n";
        return;
    }

    int mid = (l + r) >> 1;
    solve(l, mid);

    map <ll, ll> g, f;
    cur = 0;
    mn = mx = a[mid];
    bit.clear();
    
    //cout << l << " " << r << ":\n";

    ford (i, mid, l){
        addbit(a[i]);
        add(f[cur], dp[i - 1]);
        ll x = pre[mx] ^ (mn == 0 ? 0 : pre[mn - 1]) ^ pw[mn] ^ cur;
        if (x != cur)
            add(g[x], dp[i - 1]);
        //cout << i << " " << mid << " " << mn << " " << mx << " " << cur << " " << x << " " << dp[i - 1] << "\n"; 
    }

   // cout << "--\n";

    cur = 0;
    mn = mx = a[mid + 1];
    bit.clear();

    forr (i, mid + 1, r){
        addbit(a[i]);
        ll x = pre[mx] ^ (mn == 0 ? 0 : pre[mn - 1]) ^ pw[mn] ^ cur;
        add(dp[i], g[cur]);
        add(dp[i], f[x]);
        //cout << mid + 1 << " " << i << " " << mn << " " << mx << " " << cur << " " << dp[i] << "\n"; 

        //cout << x << " " << pre[mx] << " " << pw[mx] << "\n";
    }

    solve(mid + 1, r);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef hqm
        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif
    srand(time(NULL));

    cin >> n;

    forr (i, 1, n){
        cin >> a[i];
    }

    pw[0] = pre[0] = rand();

    forr (i, 1, 1000021){
        pw[i] = rand();
        pre[i] = pre[i - 1] ^ pw[i];
    }

    dp[0] = 1;

    solve(1, n);

    // forr (i, 0, n){
    //     cout << dp[i] << " " << pw[i] << "\n";
    // }

    cout << dp[n] << "\n";

    return 0;
}
/*



*/


詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 22352kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 7ms
memory: 22048kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 6ms
memory: 22336kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 22336kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 9ms
memory: 22108kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 8ms
memory: 22048kb

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 22112kb

input:

7
3 4 3 5 6 3 4

output:

3

result:

wrong answer 1st numbers differ - expected: '6', found: '3'