QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#306064#7108. CouleurMinhhoAC ✓3381ms24268kbC++174.0kb2024-01-16 11:39:482024-01-16 11:39:49

Judging History

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

  • [2024-01-16 11:39:49]
  • 评测
  • 测评结果:AC
  • 用时:3381ms
  • 内存:24268kb
  • [2024-01-16 11:39:48]
  • 提交

answer

#define taskname "G"
#include <bits/stdc++.h>
#define int long long
#define iii array<int, 3>
#define ii pair<int,int>
#define ff first
#define ss second

using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], n, a[maxn];
vector<int> fen[maxn];
map<ii,int> res;

inline void upd2(int pos, int val) {for (; pos<=n; pos+=pos&-pos) fen[pos].emplace_back(val);}
inline void upd(int pos, int val) {for (; pos<=n; pos+=pos&-pos) f[pos]+=val;}
inline int ask(int pos) {int ans=0; for(; pos; pos-=pos&-pos) ans += f[pos]; return ans;}
inline int askless(int pos, int val)
{
    int ans=0;
    for (; pos; pos-=pos&-pos)
        ans += lower_bound(fen[pos].begin(), fen[pos].end(), val) - fen[pos].begin();
        return ans;
}
inline int askmore(int pos, int val)
{
    int ans=0;
    for (; pos; pos-=pos&-pos)
        ans += fen[pos].end() - upper_bound(fen[pos].begin(), fen[pos].end(), val);
        return ans;
}
inline int qry(int l, int r) {return ask(r) - ask(l-1);}
inline int qryless(int l, int r, int val) {return askless(r, val) - askless(l-1, val);}
inline int qrymore(int l, int r, int val) {return askmore(r, val) - askmore(l-1, val);}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin.tie(nullptr); cout.tie(nullptr);
    int tst; cin>>tst; while (tst--)
    {
        cin>>n;
        res.clear();
        for (int i=1; i<=n; i++) f[i] = 0, fen[i].clear();
        int ans = 0;
        for (int i=1; i<=n; i++)
        {
            cin>>a[i];
            ans += qry(a[i]+1, n);
            upd(a[i], 1);
            upd2(i, a[i]);
        }
        for (int i=1; i<=n; i++) sort(fen[i].begin(), fen[i].end());
        for (int i=1; i<=n; i++) f[i] = 0;
        res[{1, n}] = ans;
        set<iii, greater<iii>> s;
        set<ii> seg;
        s.insert({ans, 1, n});
        seg.emplace(n, 1);
        // cout<<"BRUH: "<<n<<"\n";
        for (int i=1, x; i<=n; i++)
        {
            assert(!s.empty());
            ans = (*s.begin())[0];
            cout<<ans<<" ";
            cin>>x;
            x ^= ans;
            auto [r, l] = *seg.lower_bound({x, 0});
            int init = res[{l, r}];
            s.erase({init, l, r});
            seg.erase({r, l});
            if (r - x < x - l)
            {
                int tmp = 0, rem = 0, newval = init;
                for (int i=x+1; i<=r; i++)
                {
                    tmp += qry(a[i]+1, n);
                    upd(a[i], 1);
                    rem += qrymore(l, x, a[i]);
                }
                newval -= tmp;
                newval -= rem;
                newval -= qrymore(l, x-1, a[x]);
                for (int i=x+1; i<=r; i++) upd(a[i], -1);
                if (x+1 <= r) s.insert({tmp, x+1, r}), seg.emplace(r, x+1), res[{x+1, r}] = tmp;
                if (x-1 >= l) s.insert({newval, l, x-1}), seg.emplace(x-1, l), res[{l, x-1}] = newval;
            }
            else
            {
                int tmp = 0, rem = 0, newval = init;
                for (int i=l; i<x; i++)
                {
                    tmp += qry(a[i]+1, n);
                    upd(a[i], 1);
                    rem += qryless(x, r, a[i]);
                }
                newval -= tmp;
                newval -= rem;
                newval -= qryless(x+1, r, a[x]);
                // if (newval < 0) cout<<"BUG: "<<l<<" "<<x-1<<" "<<newval<<"\n";
                // assert(newval >= 0);
                // cout<<"HMMMMM: "<<l<<" "<<x<<" "<<r<<" "<<init<<" "<<tmp<<" "<<rem<<" "<<newval<<"\n";
                for (int i=l; i<x; i++) upd(a[i], -1);
                if (x+1 <= r) s.insert({newval, x+1, r}), seg.emplace(r, x+1), res[{x+1, r}] = newval;
                if (x-1 >= l) s.insert({tmp, l, x-1}), seg.emplace(x-1, l), res[{l, x-1}] = tmp;
            }
        }
        cout<<"\n";
    }

}
/**
 * 3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10
*/

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7496kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0 
20 11 7 2 0 0 0 0 0 0 
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3381ms
memory: 24268kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0 
12 12 10 10 4 4 4 2 1 0 
20 16 9 5 3 3 3 0 0 0 
22 14 8 8 5 5 2 1 1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
19 12 7 4 4 2 2 1 0 0 
20 18 8 3 1 1 0 0 0 0 
45 21 21 10 3 3 3 0 0 0 
17 11 8 2 1 1 1 0 0 0 
13 4 1 0 0 0 0 0 0 0 
29 27 22 15 9 7 4 3 1 0 
26 16 9 2 1 1 1 1 1 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed