QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#814908#9877. Segment Treeucup-team3691#WA 36ms5896kbC++143.4kb2024-12-14 22:22:132024-12-14 22:22:13

Judging History

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

  • [2024-12-14 22:22:13]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:5896kb
  • [2024-12-14 22:22:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

struct node {
  ll r, d; 
};

const int DIM = 3e5 + 5;
const ll INF = 1e18;

int nr;
int c[4 * DIM];
node arb[4 * DIM];

void build(int st, int dr, int nod) {
  arb[nod].r = arb[nod].d = c[nod];
  if (st == dr) {
    arb[nod].d = c[nod];
    return;
  }

  int mij = (st + dr) / 2;
  build(st, mij, nod * 2);
  build(mij + 1, dr, nod * 2 + 1);

  arb[nod].d = min(arb[nod].d, arb[nod * 2].d + arb[nod * 2 + 1].d);
}

void update(int x, int y) {
  arb[x].r = arb[x].d = y;
  while (x > 0) {
    arb[x].d = arb[x].r;
    if (x * 2 <= nr) {
      arb[x].d = min(arb[x].d, arb[x * 2].d + arb[x * 2 + 1].d);
    }
    x >>= 1;
  }
}

ll query(int x, int y, ll up, int st, int dr, int nod) {
  if (x <= st && dr <= y) {
    return min(up, arb[nod].d);
  }
  
  int mij = (st + dr) / 2;
  ll ans = 0;
  if (x <= mij) {
    ll nup = min(arb[nod].d, up) + arb[nod * 2 + 1].d;
    ans += query(x, y, nup, st, mij, nod * 2);
  }
  if (mij + 1 <= y) {
    ll nup = min(arb[nod].d, up) + arb[nod * 2].d;
    ans += query(x, y, nup, mij + 1, dr, nod * 2 + 1);
  }

  return ans;
}

void solve() {
  int n;
  cin >> n;

  int l = (1 << n);
  nr = l * 2 - 1;
  for (int i = 1; i <= nr; ++i) {
    cin >> c[i];
  }


  build(0, l - 1, 1);

  int q;
  cin >> q;

  for (int i = 1; i <= q; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      update(x, y);
    } else {
      ll ans = INF;
      if (x > y)
        swap(x, y);

      if (x == y) {
        cout << 0 << "\n";
        continue;
      }
      for (int sx = x; sx >= 0; sx -= (sx & (-sx))) {
        ll tmp = 0;
        if (sx != x) {
          tmp += query(sx, x - 1, INF, 0, l - 1, 1);
        }
        for (int sy = y; sy <= l; sy += (sy & (-sy))) {
          ll tmp2 = tmp;
          if (sy != y) {
            tmp2 += query(y, sy - 1, INF, 0, l - 1, 1);
          }
          ans = min(ans, tmp2 + query(sx, sy - 1, INF, 0, l - 1, 1));
        }

        if (sx == 0)
          break;
      }

      cout << ans << "\n";
    }
  }
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
//  cin >> t;
  while (t--)
    solve();

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5668kb

input:

3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
10
2 0 1
2 0 4
2 4 6
2 4 8
2 3 5
1 6 30
2 3 5
2 4 6
1 1 10000000
2 0 8

output:

2
1
4
8
17
18
13
15

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 22ms
memory: 5620kb

input:

1
7914575 2436426 4979445
199989
1 1 6190629
1 1 1407775
1 1 2804784
1 2 2631932
1 1 3078537
1 3 286918
1 2 3238506
1 3 3361868
1 2 9296263
1 3 4836991
1 3 2177068
1 3 4291757
1 1 594328
1 2 8996221
1 1 5531545
1 3 3575467
1 3 3206504
1 1 8344965
1 3 6045895
2 0 2
1 2 6248153
1 1 5797489
1 1 9766466...

output:

8344965
5684734
2756417
2512448
130126
7091295
7834895
6363152
6668726
4380822
8809904
4042733
8566868
8653391
3654574
7617913
8583126
4470761
4099069
2539201
7188565
8465921
4517278
1913351
7400947
5104744
1759308
6081288
3559555
3409112
3714298
8937580
4704960
5280672
9424416
1622556
2599805
18330...

result:

ok 1899 tokens

Test #3:

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

input:

1
3080713 6130142 8931932
199954
1 3 3859793
1 2 8302798
1 1 1363993
1 2 2817427
1 1 6031503
1 1 4197608
1 1 3453017
1 3 3258277
1 2 1243375
1 3 7997018
1 1 8659259
1 1 545422
1 1 1213295
1 2 9318329
1 2 1165990
1 1 3910911
1 2 9639614
1 2 3166127
1 1 2556789
1 1 2505213
2 1 2
1 1 8837030
1 1 996138...

output:

5671340
4103158
2278869
1251419
702774
1634200
9066441
3444042
4761391
1317349
996556
3444042
996556
996556
4884903
6746567
6746567
1389661
4920459
230651
935263
2028823
680623
1093324
1093324
680623
680623
369391
6136723
5192803
5192803
6136723
4301516
4578392
3566336
3566336
7599310
4756965
378391...

result:

ok 29717 tokens

Test #4:

score: 0
Accepted
time: 24ms
memory: 5672kb

input:

1
6313638 363583 8248153
199989
2 1 2
1 1 155990
1 2 4430056
2 0 2
2 1 2
1 1 6771887
1 1 9001299
2 0 1
1 3 2051074
2 1 2
2 0 1
1 1 3829876
2 0 1
1 3 8940076
2 1 2
2 0 1
2 0 2
2 0 2
1 1 2321211
1 2 8057327
2 0 2
1 1 553338
1 2 7877801
2 0 2
1 2 2505976
1 3 1153207
2 0 2
1 2 4561192
1 2 4540078
1 1 90...

output:

6677221
155990
4586046
4430056
2051074
4430056
4430056
8259932
4430056
3829876
3829876
2321211
553338
553338
5693285
4540078
4547501
5088001
1153207
3934794
1153207
3934794
3934794
3934794
7085662
3658305
3147631
3658305
6805936
3147631
3147631
853551
2267606
3727767
3727767
2645926
3727767
2645926
...

result:

ok 100061 tokens

Test #5:

score: 0
Accepted
time: 23ms
memory: 5624kb

input:

2
4716625 8732769 4896438 9294402 7273885 4137152 2249944
199996
1 1 5186587
1 4 7722585
1 5 3539426
1 5 1298070
1 6 8806800
1 1 4206062
1 6 6971489
1 5 8825000
1 5 3448517
1 6 9944200
1 1 3672387
1 2 1617483
1 5 8197902
1 6 4298339
1 5 6260453
1 2 3666548
1 3 9334704
1 3 5244559
1 3 2160729
1 6 944...

output:

5334226
9572097
4807948
733673
8100027
6139742
6091424
5926345
8623714
12325259
6201853
1162428
2792985
6816822
9147939
8703527
5455802
2767961
4607887
7567091
1326121
3115123
3452276
7483661
3901199
2876292
3890889
78252
9798360
2638886
8164525
6562024
7215100
4673524
5294603
9171516
5178543
904555...

result:

ok 2118 tokens

Test #6:

score: 0
Accepted
time: 25ms
memory: 5676kb

input:

2
1364796 5777257 6371509 2448237 9098057 7484260 6546327
199987
1 3 5999195
2 3 4
1 3 8887115
1 1 2734385
1 7 4638308
1 3 6026141
1 6 4213294
1 6 5557847
1 3 2560361
1 5 3524344
1 6 2074700
1 6 2999265
1 2 1130752
1 7 3252447
2 2 3
2 1 4
1 4 1415121
1 2 9989166
1 4 3857618
1 7 1787670
2 0 1
1 1 784...

output:

6546327
2999265
5182622
3857618
3857618
2560361
3687472
3687472
2623407
7097702
10955320
3857618
2419123
7980269
15666313
9307178
11416196
5371134
6559731
3730152
5371134
6877903
4359151
3280494
3826548
3826548
546054
2901939
6122499
1164580
4886291
2231873
4929939
10014378
1431973
5738696
3914548
1...

result:

ok 30271 tokens

Test #7:

score: 0
Accepted
time: 27ms
memory: 5896kb

input:

2
8987238 2085975 9756733 3937228 1094674 2515166 9606967
199961
2 0 1
1 4 3666395
1 3 6910698
2 0 2
1 7 8573254
2 0 2
2 1 4
1 5 3266966
2 2 3
1 1 2915552
1 1 4329051
2 0 3
1 5 4369037
1 2 6363300
2 2 3
2 1 3
2 0 2
1 1 4914198
1 3 1997323
2 0 2
2 0 4
1 4 1415720
1 4 1289499
1 2 750052
2 0 2
2 2 4
2 ...

output:

3180649
2085975
2085975
8005372
2515166
4601141
2515166
6884203
6363300
6363300
4914198
750052
1997323
3265218
4512489
4036874
4512489
4681644
4914198
3674754
1990038
5949064
5949064
1997323
5949064
2927673
4924996
3240280
1997323
2927673
5949064
1997323
8732393
3472087
2997143
5118510
6305731
19973...

result:

ok 100133 tokens

Test #8:

score: 0
Accepted
time: 17ms
memory: 5624kb

input:

3
1482396 5315709 8450176 919682 3898524 3571079 1589616 2035962 5516932 5891312 6849529 7354202 7031642 16502 9308215
199975
1 7 339038
1 13 5808906
1 4 3919992
1 5 9215343
1 11 3298396
1 8 5150388
1 5 8504301
1 8 6918145
1 3 9033980
1 6 5735807
1 13 4288323
1 10 8374520
1 10 7379361
1 10 4528048
1...

output:

16285940
5238493
5238493
22472855
4669470
9602957
8393079
10020309
10254346
9573978
8514546
1334143
5464242
3719349
3301995
7390632
14498
8915141
14146684
6366701
3961165
16556363
7660670
703615
6012909
8926254
2066592
119507
3915410
342821
5297748
4461720
14683484
6646771
9060221
16652253
5539517
2...

result:

ok 1998 tokens

Test #9:

score: 0
Accepted
time: 25ms
memory: 5680kb

input:

3
7876562 7918635 6176833 4520847 6020244 5083916 622852 1770395 1392360 8442457 9525646 7836026 7109198 1592189 2928475
199969
1 3 1211323
1 12 6475000
1 4 6251690
1 13 4588701
2 2 4
1 13 2830484
1 9 5455590
1 2 4199941
2 4 5
1 11 4237912
1 8 8616532
1 2 7013262
1 15 1447432
1 10 1885793
1 1 302428...

output:

6020244
4664659
6251690
2864338
12620842
4663182
2809904
3300986
4297387
491082
8535859
4663334
10090113
2286459
5010204
9102340
6155733
7634549
11501377
3479332
7732994
5676990
5079349
7705518
11300621
13032232
6363537
7777507
2257343
13773540
6235980
4805506
6429254
4494831
8735088
7368501
5269100...

result:

ok 29959 tokens

Test #10:

score: 0
Accepted
time: 36ms
memory: 5676kb

input:

3
6577234 7854127 1080391 5145959 8947475 6924960 2198194 754421 9124876 764427 1234813 50367 6595762 5221022 9057974
199974
2 1 4
1 5 5912881
2 2 4
1 7 1124351
2 4 7
2 5 7
2 4 5
1 13 2139694
2 0 5
1 8 6713651
2 1 6
1 15 7871410
2 6 8
2 6 8
2 2 5
1 9 4197528
1 5 6876249
1 12 618638
1 2 5353143
2 0 4...

output:

7899620
1999240
7425764
7476131
50367
7195566
13314177
1124351
1124351
2049607
5353143
2617878
3439555
2139694
9425004
1080391
764427
5353143
1124351
2315204
764427
1124351
10555137
2617878
5482720
5593182
15776159
7481960
4961955
7481960
10493849
4358369
10814204
5221022
6357609
5294962
2276892
435...

result:

ok 99699 tokens

Test #11:

score: -100
Wrong Answer
time: 27ms
memory: 5744kb

input:

6
6200813 2937593 7123154 7432392 9485632 271055 259223 1031893 8048638 4986334 3959447 7363320 1413621 971860 1688778 3534103 8309348 230130 3140570 7936752 1761922 8489742 7183013 8868752 4570229 2227218 4385599 1790428 610780 2973050 8497517 4637452 5834054 4557274 3328810 6585387 7311801 2692566...

output:

9806870
5065647
15037432
13145568
31811559
16007715
11448517
4198846
14424470
4756010
16520128
23458763
14417200
14090570
17775435
7820363
12633290
19577002
11428882
9369697
20525007
10589716
5994180
17140937
21105217
11881698
5967192
10477168
12361991
24044637
17593684
7190071
14655343
13995199
112...

result:

wrong answer 5th words differ - expected: '31482337', found: '31811559'