QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187254#3850. DJ DarkorealIyxiang#WA 558ms22600kbC++143.1kb2023-09-24 15:48:032023-09-24 15:48:04

Judging History

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

  • [2023-09-24 15:48:04]
  • 评测
  • 测评结果:WA
  • 用时:558ms
  • 内存:22600kb
  • [2023-09-24 15:48:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 2e5 + 5;
struct node { 
  int l, r; 
  bool operator < (const node &x) const {
    return l == x.l ? r < x.r : l < x.l; 
  }  
} u, st[N]; 
int n, q, l, r, x, op, tp, a[N], b[N];  
set <node> S;  

namespace FT {
  int c[N]; 
  
  void add (int p, int k) {
    for (int i = p; i <= n; i += (i & (-i)))
      c[i] += k; 
  }
  void upd (int l, int r, int k) {
    add(l, k), add(r + 1, -k); 
  }
  int qry (int p) {
    int ans = 0; 
    for (int i = p; i; i -= (i & (-i)))
      ans += c[i]; 
    return ans; 
  }
}

void split (int p) {
  if(p > n) return ; 
  auto it = S.upper_bound((node){p, n + 1}); --it; 
  node u = *it; 
  S.erase(u); 
  if(u.l != p) S.insert((node){u.l, p - 1});
  S.insert((node){p, u.r});
  int val = FT :: qry(u.l);
  FT :: upd(p, p, -FT :: qry(p));    
  FT :: upd(p, p, val); 
  a[p] = a[u.l]; 
}
void update (int l, int r, int x) {
  a[l] = x, FT :: upd(l, l, -FT :: qry(l)); 
  split(l), split(r + 1); 
  auto itl = S.lower_bound((node){l, 0});
  auto itr = S.lower_bound((node){r + 1, 0});
  for (auto it = itl; it != itr; ++it) st[++tp] = (*it); 
  // cout << "upd : \n"; 
  for ( ; tp; --tp) S.erase(st[tp])/*, cout << st[tp].l << ' ' << st[tp].r << '\n'*/; 
  S.insert((node){l, r});
}
bool check (int v) {
  int s = 0, cur = 0; node u; 
  auto itl = S.lower_bound((node){l, 0});
  auto itr = S.lower_bound((node){r + 1, 0});
  for (auto it = itl; it != itr; ++it) {
    u = *it; 
    s += b[u.l] * (u.r - u.l + 1); 
    // cerr << "! : " << u.l << ' ' << u.r << ' ' << a[u.l] << '\n'; 
    if(a[u.l] <= v) cur += b[u.l] * (u.r - u.l + 1)/*, cerr << "! : " << a[u.l] << ' ' << u.l << ' ' << u.r << '\n'*/; 
  }
  // cerr << v << ' ' << s << ' ' << cur << '\n'; 
  return cur >= s / 2; 
}
void print () {
  cout << "print : " << '\n'; 
  for (auto it : S) {
    u = it; 
    cout << u.l << ' ' << a[u.l] + FT :: qry(u.l) << '\n'; 
  }
}

signed main () {
  scanf("%lld%lld", &n, &q); 
  rep(i, 1, n) scanf("%lld", &a[i]); 
  rep(i, 1, n) scanf("%lld", &b[i]); 
  rep(i, 1, n) S.insert((node){i, i}); 
  while (q--) {
    scanf("%lld%lld%lld", &op, &l, &r); 
    if(op == 1) {
      scanf("%lld", &x); 
      FT :: upd(l, r, x); 
    } else {
      split(l), split(r + 1); 
      auto itl = S.lower_bound((node){l, 0});
      auto itr = S.lower_bound((node){r + 1, 0});
      for (auto it = itl; it != itr; ++it) {
        u = *it; 
        a[u.l] += FT :: qry(u.l), FT :: upd(u.l, u.l, -FT :: qry(u.l)); 
      }
      int vl = -1e16, vr = 1e16; 
      while (vl < vr) {
        int Mid = vl + vr;
        if(Mid < 0) Mid = (Mid - 1) / 2;
        else Mid = Mid / 2; 
        // cerr << vl << ' ' << vr << ' ' << Mid << ' ' << check(Mid) << '\n'; 
        if(check(Mid)) vr = Mid;
        else vl = Mid + 1; 
      }
      update(l, r, vl); 
      printf("%lld\n", vl); 
    }
    // print(); 
    // cerr << "ok : " << q << '\n'; 
  }
  return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 558ms
memory: 22600kb

input:

200000 200000
185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...

output:

462406736
1749348519
1749348519
467651597
1749348519
1749348519
1749348519
1749348519
873765076
1749348519
-893932302
449782566
716070728
449782566
449782566
449782566
449782566
449782566
449782566
449782566
449782566
197810390
197810390
197810390
-553194255
1284798792
714479242
714479242
714479242
...

result:

wrong answer 5th lines differ - expected: '874061694', found: '1749348519'