QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222948#7615. Sequence Foldingucup-team2307#TL 1ms3476kbC++142.7kb2023-10-21 20:00:442023-10-21 20:00:44

Judging History

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

  • [2023-10-21 20:00:44]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3476kb
  • [2023-10-21 20:00:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)

struct dsu {
    int res = 0;
    vector<int> e;
    dsu(int n) :e(n, -1) {}
    int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
    void join(int u, int v) {
        u = find(u), v = find(v);
        if(u == v) return;
        if(-e[u] < -e[v]) swap(u, v);
        
        res -= (-e[u]) / 2;
        res -= (-e[v]) / 2;

        e[u] += e[v];
        e[v] = u;

        res += (-e[u]) / 2;
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);
    // int t;
    // cin >> t;
    // while(t--) {
    //     string s, t;
    //     cin >> s >> t;
    //     array<int, 26> cS, cT;
    //     cS.fill(0); cT.fill(0);
    //     for(auto &i : s) cS[i - 'a']++;
    //     for(atuo &i : t) cT[i - 'a']++;
    //     int cyc = 0, ok = 0;
    //     while(!ok) {
    //         cyc++;
    //         int v = -1;
    //         for(auto i : cT) {
    //             i /= cyc;
    //             v = v == -1 ? i : v;
    //             v = v == i ? v : -2;
    //         } 
    //         ok = v >= 0;
    //     }
        
    //     for(int x = 0; x < 26; x++) {
        
    //     }
    // // }
    // int n;
    // cin >> n;
    // vector<ll> a(n), ans(n / 2 + 1, 1ll<<60);
    // vector<array<ll, 2>> b;
    // for(auto &i : a) cin >> i;
    // sort(all(a));
    // for(int i = 1; i < n; i++) {
    //     b.push_back({a[i] - a[i - 1], i});
    // }
    // sort(all(b));
    // dsu d(n);
    // for(auto &[v, i] : b) {
    //     d.join(i - 1, i);
    //     ans[d.res] = min(ans[d.res], v);
    // }
    // ans.erase(ans.begin());
    // for(auto i : ans) cout << i << ' '; cout << endl;
    ll n, m;
    cin >> n >> m;
    vector<array<ll, 2>> nonz(m);
    for(auto &[x, v] : nonz) cin >> x, v = 1, x--;
    sort(all(nonz));
    int ops = 0;
    while(n > 1) {
        int l = 0, r = (int)nonz.size() - 1;
        vector<array<ll, 2>> nonz2;
        while(l <= r) {
            int D = min(nonz[l][0], n - 1 - nonz[r][0]);
            int L = nonz[l][0] == D ? nonz[l][1] : 0;
            int R = n - 1 - nonz[r][0] == D ? nonz[r][1] : 0;
            // cout << D << " " << L << " " << R << endl;
            if(L == 2 || R == 2) {
                nonz2.push_back({D, L ^ R ^ 2});
            } else {
                ops += L != R;
                nonz2.push_back({D, L == R ? L : 2});
            }
            l += nonz[l][0] == D;
            r -= n-1-nonz[r][0] == D;
        }
        n /= 2;
        sort(all(nonz2));
        nonz = nonz2;
        // for(auto [x, v] : nonz) cout << x << " " << v << endl;
        // cout << endl;
    }
    cout << ops << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3472kb

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Time Limit Exceeded

input:

17179869184 100000
138476 774165 993977 1152277 1236393 1244970 1534017 1693701 1763926 1778781 1842066 1874644 1885666 2120429 2485344 2977941 3158255 3340476 3504862 4000117 4066652 4197639 4338723 4389163 4576965 4761601 5097091 5175412 5295902 5810551 5855982 6001770 6111262 6163309 6351547 6582...

output:


result: