QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334505#5358. 宝石游戏bobbilyking0 497ms46984kbC++203.2kb2024-02-22 02:03:032024-02-22 02:03:04

Judging History

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

  • [2024-02-22 02:03:04]
  • 评测
  • 测评结果:0
  • 用时:497ms
  • 内存:46984kb
  • [2024-02-22 02:03:03]
  • 提交

answer

// Test d2d on https://codeforces.com/contest/893/problem/F
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;

#define G(x) ll x; cin >> x;
#define F(i, l, r) for(ll i = l; i < (r); ++i)
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define A(a) (a).begin(), (a).end()
#define N 100010
ll tin[N], tout[N], dep[N];
vl adj[N];

void dfs(ll i, ll p) {
    dep[i] = dep[p]+1;
    static int time = 0;
    tin[i] = time++;
    for (ll x: adj[i]) if (x-p) dfs(x, i);
    tout[i] = time;
}

namespace d2d {
    using key_t = int;
    using T = int;
    
    T id = 0;
    T f(T a, T b) {return a^b;}
    
    struct seg {
        vector<T> t;
        vector<key_t> rr;
        #define rein(x) (lower_bound(A(rr), x) - rr.begin() + rr.size())
        void modify(key_t pin, T value) {  // set value at position p
            int p = rein(pin);
            // assert(p != 2 * rr.size() and rr[p - rr.size()] == pin);
            for (t[p] = value; p /= 2;) t[p] = f(t[2*p], t[2*p+1]);
        }
    
        T query(key_t lin, key_t rin) { // fold f on interval [l, r)
            T resl=id, resr=id;
            for (int l = rein(lin), r = rein(rin); l < r; l /= 2, r /= 2) {
                if (l&1) resl = f(resl, t[l++]);
                if (r&1) resr = f(t[--r], resr);
            }
            return f(resl, resr);
        }
        #undef rein
    } t[2*N];

// setup functions
    void build() { 
        F(i, 0, N*2) {
            auto &rr = t[i].rr;
            sort(A(rr));
            rr.erase(unique(A(rr)), rr.end());
            t[i].t.assign(2*rr.size(), id);
        }
    }

    void pre_modify(int p, key_t k) {
        for (p+=N, t[p].rr.push_back(k); p /= 2;) t[p].rr.push_back(k);
    }

// actual functions
    void modify(int p, key_t k, int v) { 
        for (p+=N, t[p].modify(k, v); p /= 2;) t[p].modify(k, v);
    }

    T query(int l, int r, key_t l2, key_t r2) { // queries f(..[l2, r2)..) for all segtrees [l, r)
        T res = id;
        for(l += N, r += N; l < r; l /= 2, r /= 2) {
            if(l & 1) res = f(t[l++].query(l2, r2), res);
            if(r & 1) res = f(res, t[--r].query(l2, r2));
        }
        return res;
    }
}

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);

    G(n) G(q)
    {
        vl a(n+1);
        F(i, 1, n+1) cin >> a[i];
        F(i, 0, n-1) {
            G(x) G(y) adj[x].push_back(y); adj[y].push_back(x);
        }    
        dfs(1, 1);
        F(i, 1, n+1) d2d::pre_modify(tin[i], dep[i]);
        d2d::build();
        F(i, 1, n+1) d2d::modify(tin[i], dep[i], a[i]);
    }
    
    ll last = 0;
    while(q--) {
        G(t) G(i) G(L)
        if (t == 1) {
            d2d::modify(tin[i], dep[i], L);
        } else {
            last = d2d::query(tin[i], tout[i], dep[i], dep[i] + L + 1);
            cout << last << '\n';
        }
    }
    
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 2ms
memory: 3596kb

input:

7 5
1 2 3 4 5 6 7
3 1
2 4
3 7
6 7
5 4
4 1
2 1 1
2 4 0
2 7 2
1 6 0
2 7 1

output:

6
4
1
7

result:

ok 4 lines

Test #2:

score: -7
Wrong Answer
time: 5ms
memory: 4240kb

input:

1000 1000
168301431 651266519 181230331 997564131 922958564 240686472 828844423 997226083 101127334 549182223 815802272 962217487 872007143 308493550 875871642 388491137 726655288 632336322 36483715 91926885 973887125 969715766 903583959 709995095 551483747 454472802 645719871 210282402 246763026 76...

output:

1042345766
1025716686
273570986
787008786
223203217
454842670
149835872
10858105
789658324
79729859
833835681
261518631
614070373
177228933
61850199
539713605
653065960
889140091
449348615
1065471152
446664287
3976935
531033694
85265826
30973706
618756576
129885029
921984181
362723620
1064115649
210...

result:

wrong answer 1st lines differ - expected: '13348898220', found: '1042345766'

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 464ms
memory: 43164kb

input:

100000 100000
405003099 610837546 348589233 875137317 862931320 731758484 582603782 989991623 184749683 961137536 740146957 148627391 849777698 445045421 119699522 266347287 445197848 974544475 91680144 328247730 665144499 422991113 252383902 770011580 393442268 470439648 712319066 315986988 4789186...

output:

628488280
747543671
48940353
594554410
551063854
1058806505
855845244
962254399
841425155
727173879
550289640
502601409
857432062
545225207
534191912
409515795
1008460858
639354254
530775075
307664112
369201126
476033096
292934214
494997148
966179342
960496538
302583051
272568417
713219118
436864447...

result:

wrong answer 1st lines differ - expected: '981730896', found: '628488280'

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 497ms
memory: 46984kb

input:

100000 100000
391636738 188947351 607003168 699971181 102753269 291890533 830830147 76057458 623517854 58958317 449828617 773557323 669394342 548355126 601286710 238603435 809091745 772998770 894693501 564199529 196062134 2803096 781469712 870912328 138245421 273392139 476952377 787775209 401014779 ...

output:

866428712
137851917
401667046
75988306
831105660
700286146
664101969
713211112
167736362
121213840
640496112
704836035
220748678
677890991
602803283
14428621
807945455
923422847
467527154
975591439
199253422
457591807
818425106
296851124
969444268
804603994
989224555
557066793
1059515420
35403797
20...

result:

wrong answer 1st lines differ - expected: '4014146821', found: '866428712'

Subtask #4:

score: 0
Wrong Answer

Test #26:

score: 0
Wrong Answer
time: 454ms
memory: 43220kb

input:

100000 100000
620733757 384382313 514191349 902009280 482178057 905939364 286556695 762555921 287205978 88334200 437152915 320217018 981790168 254780145 881516456 779810222 814317342 292303220 272120273 65511383 98150102 177581894 12582058 656218139 789187030 442791738 134622788 62465827 954191430 1...

output:

298915582
999885318
699528452
965328649
319322982
272507771
20449414
422669355
65995163
573595988
400940617
933697401
160195054
1003960982
553925275
1068049140
170780548
381220163
194372500
478991741
461391411
990850705
384738621
322234264
708118271
1070307977
970877051
929551313
113451781
243407470...

result:

wrong answer 1st lines differ - expected: '11993349061', found: '298915582'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%