답안 #731373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731373 2023-04-27T11:17:55 Z AdamGS Modern Machine (JOI23_ho_t5) C++17
25 / 100
3000 ms 3120 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=12e4+7;
char C[LIM];
int tr[4*LIM], lazy[4*LIM], T[LIM], N=1, n, m, q;
void spl(int v, int l, int r) {
  tr[2*v]=lazy[v]*(r-l+1)/2;
  tr[2*v+1]=lazy[v]*(r-l+1)/2;
  lazy[2*v]=lazy[2*v+1]=lazy[v];
  lazy[v]=-1;
}
void upd(int v, int l, int r, int a, int b, int x) {
  if(l>b || r<a) return;
  if(a<=l && r<=b) {
    tr[v]=(r-l+1)*x;
    lazy[v]=x;
    return;
  }
  if(lazy[v]!=-1) spl(v, l, r);
  int mid=(l+r)/2;
  upd(2*v, l, mid, a, b, x);
  upd(2*v+1, mid+1, r, a, b, x);
  tr[v]=tr[2*v]+tr[2*v+1];
}
int cnt(int v, int l, int r, int a, int b) {
  if(l>b || r<a) return 0;
  if(a<=l && r<=b) return tr[v];
  if(lazy[v]!=-1) spl(v, l, r);
  int mid=(l+r)/2;
  return cnt(2*v, l, mid, a, b)+cnt(2*v+1, mid+1, r, a, b);
}
int znajdzb(int v, int l, int r, int k) {
  if(l==r) return l;
  if(lazy[v]!=-1) spl(v, l, r);
  int mid=(l+r)/2;
  int x=(mid-l+1)-tr[2*v];
  if(x>=k) return znajdzb(2*v, l, mid, k);
  return znajdzb(2*v+1, mid+1, r, k-x);
}
int znajdzr(int v, int l, int r, int k) {
  if(l==r) return l;
  if(lazy[v]!=-1) spl(v, l, r);
  int mid=(l+r)/2;
  int x=tr[2*v+1];
  if(x>=k) return znajdzr(2*v+1, mid+1, r, k);
  return znajdzr(2*v, l, mid, k-x);
}
void symuluj(int x) {
  int iler=cnt(1, 0, N-1, 0, x-1), ileb=n-x-1-cnt(1, 0, N-1, x+1, n-1), p=cnt(1, 0, N-1, x, x);
  if(iler<ileb) upd(1, 0, N-1, 0, znajdzb(1, 0, N-1, x+1+1-p), 1);
  else upd(1, 0, N-1, znajdzr(1, 0, N-1, n-x+p-1), n-1, 0);
}
void brutq() {
  while(N<n) N*=2;
  while(q--) {
    rep(i, 2*N) tr[i]=0;
    rep(i, n) if(C[i]=='R') tr[N+i]=1;
    for(int i=N-1; i; --i) tr[i]=tr[2*i]+tr[2*i+1];
    rep(i, 2*N) lazy[i]=-1;
    int l, r;
    cin >> l >> r; --l; --r;
    while(l<=r) {
      symuluj(T[l]);
      ++l;
    }
    cout << tr[1] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> n >> m;
  rep(i, n) cin >> C[i];
  rep(i, m) {
    cin >> T[i];
    --T[i];
  }
  cin >> q;
  if(q<=5) {
    brutq();
    return 0;
  }
  brutq();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 246 ms 3020 KB Output is correct
19 Correct 335 ms 3004 KB Output is correct
20 Correct 455 ms 3016 KB Output is correct
21 Correct 487 ms 3012 KB Output is correct
22 Correct 325 ms 3120 KB Output is correct
23 Correct 288 ms 2996 KB Output is correct
24 Correct 262 ms 2980 KB Output is correct
25 Correct 260 ms 2952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 3068 ms 724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 3068 ms 724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 3068 ms 724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 246 ms 3020 KB Output is correct
19 Correct 335 ms 3004 KB Output is correct
20 Correct 455 ms 3016 KB Output is correct
21 Correct 487 ms 3012 KB Output is correct
22 Correct 325 ms 3120 KB Output is correct
23 Correct 288 ms 2996 KB Output is correct
24 Correct 262 ms 2980 KB Output is correct
25 Correct 260 ms 2952 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Execution timed out 3068 ms 724 KB Time limit exceeded
28 Halted 0 ms 0 KB -