QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#32691#2571. Aidana and PitaYaoBIG#AC ✓914ms58156kbC++174.1kb2022-05-22 23:32:142022-05-22 23:32:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-22 23:32:16]
  • 评测
  • 测评结果:AC
  • 用时:914ms
  • 内存:58156kb
  • [2022-05-22 23:32:14]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i,a,n) for(auto i=a;i<=n;i++)
#define per(i,a,n) for(auto i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define all(A) A.begin(),A.end()
#define sz(A) (int)A.size()
template<class T> inline bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; }
template<class T> inline bool chmin(T &a, T b) { if(b < a) {a = b; return 1;} return 0; }
using namespace std;

template<class A, class B> string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string) s); }
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(bool x) { return x ? "true" : "false"; }
template<class A> string to_string(A v) 
{
    bool first = 1;
    string res = "{";
    for(const auto &x: v) 
    {
        if (!first) res += ", ";
        first = 0;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template<class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.FI) + ", " + to_string(p.SE) + ")"; }

void debug_out() { cerr << endl; }
template<class Head, class... Tail> void debug_out(Head H, Tail... T) 
{
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef ONLINE_JUDGE
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) if(0) puts("No effect.")
#endif

using ll = long long;
// using LL = __int128;
using pii = pair<int,int>;
using vi = vector<int>;
using db = double;
using ldb = long double;

const int maxn = 2'000'000;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

template<class T, T INF, int maxn> struct BIT
{
    int n;
    T a[maxn + 5];
    int id[maxn + 5];
    void init(int _n)
    {
        n = _n;
        rep(i, 1, n) a[i] = -INF;
    }
    void add(int i, T x, int y) { for(; i <= n; i += i & -i) if(chmax(a[i], x)) id[i] = y; }
    pair<T, int> ask(int i)
    {
        T ans = -INF;
        int ID = -1;
        for(; i; i -= i & -i) if(chmax(ans, a[i])) ID = id[i];
        return mp(ans, ID);
    }
};

int main()
{
    static int pw[25];
    pw[0] = 1;
    rep(i, 1, 15) pw[i] = pw[i - 1] * 3;

    int n; scanf("%d", &n);
    vi a(n);
    for(auto &x: a) scanf("%d", &x);
    vi L = vi(a.begin(), a.begin() + n / 2);
    vi R = vi(a.begin() + n / 2, a.end());
    vector<pair<pii, int>> A, B;
    function<void(vector<pair<pii, int>>&, vi&, int, int, int, int, int)> dfs = [&](vector<pair<pii, int>> &res, vi &vec, int dep, int A, int D, int B, int msk)
    {
        if(dep == sz(vec))
        {
            res.pb(mp(pii{A - D, D - B}, msk));
            return;
        }
        dfs(res, vec, dep + 1, A + vec[dep], D, B, msk);
        dfs(res, vec, dep + 1, A, D + vec[dep], B, msk + pw[dep]);
        dfs(res, vec, dep + 1, A, D, B + vec[dep], msk + pw[dep] * 2);
    };
    dfs(A, L, 0, 0, 0, 0, 0);
    dfs(B, R, 0, 0, 0, 0, 0);
    for(auto &[it, msk]: B) it = {-it.FI, -it.SE};
    sort(all(A));
    sort(all(B)); reverse(all(B));
    vi vec;
    for(auto [it, msk]: B) vec.pb(it.SE);
    sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
    int N = sz(vec);
    auto getid = [&](int x) { return lower_bound(all(vec), x) - vec.begin() + 1; };
    static BIT<int, inf, maxn> bit;
    bit.init(N);
    assert(N <= maxn);
    int best = inf;
    pii ansmsk = {-1, -1};
    for(auto [it, msk]: A)
    {
        auto [x1, y1] = it;
        while(sz(B) && B.back().FI.FI <= x1)
        {
            auto [x2, y2] = B.back().FI;
            int msk = B.back().SE;
            B.pop_back();
            int pos = getid(y2);
            bit.add(pos, x2 + y2, msk);
        }
        auto pos = getid(y1 + 1) - 1;
        auto [mx, msk2] = bit.ask(pos);
        if(chmin(best, x1 + y1 - mx)) ansmsk = {msk, msk2};
    }
    vi ans;
    auto [X, Y] = ansmsk;
    rep(i, 1, n / 2) ans.pb(X % 3), X /= 3;
    rep(i, 1, n - n / 2) ans.pb(Y % 3), Y /= 3;
    rep(i, 0, n - 1) printf("%d%c", ans[i] + 1, " \n"[i == n - 1]);
    return 0;
}

詳細信息

Test #1:

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

input:

5
2 3 1 4 2

output:

3 2 2 1 3

result:

ok answer is 0

Test #2:

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

input:

6
3 2 5 3 4 2

output:

2 3 1 2 3 1

result:

ok answer is 1

Test #3:

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

input:

3
2617460 3290620 1468912

output:

2 1 3

result:

ok answer is 1821708

Test #4:

score: 0
Accepted
time: 363ms
memory: 44204kb

input:

25
6 6 7 8 5 10 5 7 10 10 4 4 5 8 1 6 3 1 9 4 10 7 8 4 5

output:

3 2 3 3 2 3 2 2 2 2 2 2 3 3 3 3 1 1 1 1 1 1 1 1 1

result:

ok answer is 0

Test #5:

score: 0
Accepted
time: 351ms
memory: 44304kb

input:

25
8 2 2 9 9 10 3 5 9 1 2 5 8 1 4 8 4 3 6 2 8 8 4 2 2

output:

2 3 3 3 2 3 2 2 2 2 2 2 3 1 3 1 1 1 3 1 1 1 1 1 1

result:

ok answer is 1

Test #6:

score: 0
Accepted
time: 378ms
memory: 43216kb

input:

25
9999996 9999999 9999991 9999991 9999999 9999997 9999991 9999993 9999992 10000000 9999991 10000000 9999996 9999997 9999993 9999992 9999990 9999991 9999997 10000000 9999998 9999990 9999993 9999990 9999999

output:

2 2 1 1 2 3 1 2 2 2 1 2 2 3 3 1 1 1 3 3 3 1 3 1 3

result:

ok answer is 9999943

Test #7:

score: 0
Accepted
time: 352ms
memory: 45348kb

input:

25
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000

output:

3 3 3 3 2 2 2 2 2 2 2 2 3 3 3 3 1 1 1 1 1 1 1 1 1

result:

ok answer is 10000000

Test #8:

score: 0
Accepted
time: 896ms
memory: 57440kb

input:

25
4568194 6252832 2990361 6179671 5525735 3402540 12193 4812907 2393092 9823299 4089880 1724585 2200631 5143163 5750864 5341161 5957736 2310544 8033121 9675751 9295231 71902 6463783 7667395 5613033

output:

1 3 3 3 3 3 2 2 2 1 1 3 3 2 3 1 1 1 2 1 2 3 2 3 2

result:

ok answer is 49

Test #9:

score: 0
Accepted
time: 911ms
memory: 56168kb

input:

25
7762025 9149481 7523209 4813111 6800820 1960599 4807700 5411348 4528299 7599785 3468951 537831 6539799 2655771 1259341 9722159 506693 2973008 7910966 3611985 6228870 4141646 9112851 1735188 6538160

output:

3 1 2 3 1 3 3 2 3 3 2 2 3 3 3 1 3 1 1 2 2 1 2 1 2

result:

ok answer is 145

Test #10:

score: 0
Accepted
time: 909ms
memory: 56684kb

input:

25
4732744 6239034 6860504 9029957 848680 209411 3629865 1309532 7860007 2831327 1707125 320774 4082248 4458046 8318819 7279399 861428 5020696 716989 8764261 952311 9612131 5994738 7283372 5509248

output:

3 3 3 1 3 3 3 2 2 3 2 2 2 1 1 2 1 2 1 1 2 2 1 3 3

result:

ok answer is 53

Test #11:

score: 0
Accepted
time: 854ms
memory: 57536kb

input:

25
3926971 5832018 518527 8763702 973269 4552634 6533999 2808656 1277522 5063756 3389181 9876771 4222160 9001717 3592108 5852492 7874646 507942 8922016 4798000 1131210 9081684 512549 3399413 3253241

output:

3 2 2 1 3 2 3 2 2 1 2 1 2 3 3 2 3 2 1 1 1 2 2 3 3

result:

ok answer is 91

Test #12:

score: 0
Accepted
time: 878ms
memory: 57048kb

input:

25
9383440 7906533 1692080 1331860 34750 3968473 2920448 8420499 271149 5986045 9894611 508079 1328124 2344042 9426700 8381332 7038317 4146561 5946221 3554163 215270 6084580 2549278 2162818 3791345

output:

1 2 1 3 3 3 3 1 3 2 1 2 3 3 3 2 1 2 2 2 3 3 3 3 3

result:

ok answer is 110

Test #13:

score: 0
Accepted
time: 882ms
memory: 56876kb

input:

25
4046088 7315708 7288467 1966990 9827334 4635838 8767858 753173 7611802 8291513 4297560 3224050 8917952 5408746 3999749 761012 1332251 409871 2394270 1464938 7524338 2072107 3597866 4231339 9638829

output:

2 3 2 2 1 1 2 1 1 3 3 2 3 1 2 1 1 2 2 3 1 1 2 2 3

result:

ok answer is 101

Test #14:

score: 0
Accepted
time: 897ms
memory: 55884kb

input:

25
5547618 2099625 1573205 2912509 2335015 318412 5812834 9389294 7275632 2026666 7297673 3627332 1756646 7605338 5450938 6407663 678114 5237576 4788058 1293302 5458419 9269556 9795138 6180722 2919003

output:

3 2 3 3 2 2 3 1 2 3 1 3 3 3 1 1 1 3 2 2 2 2 1 2 3

result:

ok answer is 93

Test #15:

score: 0
Accepted
time: 914ms
memory: 57636kb

input:

25
58653 5582060 2162966 9667782 5952067 1573434 692941 6120542 1083586 5478323 762427 4922098 3516225 9558027 2481388 1525866 1640140 5470075 6840333 8007024 520149 1766849 496240 7801716 7498415

output:

2 1 2 2 3 1 3 1 3 3 3 3 2 2 1 2 1 2 3 1 1 2 3 1 3

result:

ok answer is 23

Test #16:

score: 0
Accepted
time: 410ms
memory: 45872kb

input:

25
911 78 35 7 73 7 74 57 40 54 71 15 78 931 29 51 12 953 47 18 44 51 27 62 16

output:

2 3 2 2 2 2 2 3 3 2 2 2 3 3 1 3 3 1 1 1 1 1 1 1 1

result:

ok answer is 0

Test #17:

score: 0
Accepted
time: 718ms
memory: 52792kb

input:

25
56582 31593 65868 9990302 89743 29492 69983 10894 37205 19856 32444 9930060 97648 56666 17128 53655 30899 48933 58260 51304 83008 96129 1061 11962 9941936

output:

1 2 3 2 2 2 1 3 2 3 3 3 3 1 1 1 2 1 1 3 2 3 1 2 1

result:

ok answer is 1

Test #18:

score: 0
Accepted
time: 413ms
memory: 45608kb

input:

25
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 6257913

output:

3 3 2 2 2 2 2 3 3 2 2 2 2 2 3 2 2 2 2 2 3 2 2 1 3

result:

ok answer is 1065348

Test #19:

score: 0
Accepted
time: 555ms
memory: 56428kb

input:

25
1 3 9 27 81 243 729 2187 6561 19683 59049 177147 531441 1594323 4782969 1088916 1520954 9015711 5552512 1853562 2760187 8617948 6012543 456601 6151460

output:

3 3 3 3 3 3 2 3 2 2 3 1 2 3 1 2 3 1 3 3 1 2 2 2 3

result:

ok answer is 1603

Test #20:

score: 0
Accepted
time: 377ms
memory: 45916kb

input:

25
1 10 100 1000 10000 100000 1000000 10000000 69 45 74 74 33 29 35 55 1 43 50 86 10 81 29 96 73

output:

3 3 3 3 3 3 2 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

result:

ok answer is 9888006

Test #21:

score: 0
Accepted
time: 326ms
memory: 44932kb

input:

25
1 15 225 3375 50625 759375 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

3 3 3 3 2 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

result:

ok answer is 755740

Test #22:

score: 0
Accepted
time: 330ms
memory: 45716kb

input:

25
1 20 400 8000 160000 3200000 1 1 1 1 1 1 1 2 1 2 1 2 1 2 2 2 2 2 2

output:

3 3 3 3 2 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

result:

ok answer is 3191551

Test #23:

score: 0
Accepted
time: 842ms
memory: 58156kb

input:

25
63353 736041 846599 1431744 1739144 2274384 2726277 3192576 3288972 3897012 4065841 4471346 4818261 5270407 5717802 6224939 6449270 6970979 7252374 7847142 8218821 8775107 8869918 9324673 9686751

output:

2 3 1 1 1 3 3 2 1 2 2 3 1 2 3 1 3 1 2 1 1 2 2 3 3

result:

ok answer is 57