結果

問題 No.2422 regisys?
ユーザー SSRSSSRS
提出日時 2023-08-12 14:24:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 2,516 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 179,596 KB
実行使用メモリ 15,576 KB
最終ジャッジ日時 2024-04-30 06:00:14
合計ジャッジ時間 11,053 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 127 ms
6,940 KB
testcase_32 AC 199 ms
10,832 KB
testcase_33 AC 113 ms
6,940 KB
testcase_34 AC 86 ms
6,944 KB
testcase_35 AC 138 ms
6,944 KB
testcase_36 AC 144 ms
8,320 KB
testcase_37 AC 210 ms
10,984 KB
testcase_38 AC 157 ms
9,900 KB
testcase_39 AC 106 ms
7,424 KB
testcase_40 AC 74 ms
6,944 KB
testcase_41 AC 105 ms
7,168 KB
testcase_42 AC 239 ms
8,588 KB
testcase_43 AC 151 ms
8,064 KB
testcase_44 AC 264 ms
9,256 KB
testcase_45 AC 218 ms
8,256 KB
testcase_46 AC 262 ms
9,332 KB
testcase_47 AC 174 ms
8,320 KB
testcase_48 AC 249 ms
8,336 KB
testcase_49 AC 223 ms
9,532 KB
testcase_50 AC 218 ms
7,356 KB
testcase_51 AC 370 ms
14,436 KB
testcase_52 AC 112 ms
6,940 KB
testcase_53 AC 265 ms
10,004 KB
testcase_54 AC 358 ms
14,040 KB
testcase_55 AC 265 ms
10,296 KB
testcase_56 AC 254 ms
11,980 KB
testcase_57 AC 423 ms
15,576 KB
testcase_58 AC 427 ms
15,504 KB
testcase_59 AC 425 ms
15,504 KB
testcase_60 AC 433 ms
15,508 KB
testcase_61 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
template <typename T>
struct lazy_segment_tree{
	int N;
	vector<T> ST;
	vector<T> lazy;
	lazy_segment_tree(vector<int> &A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, -INF);
		lazy = vector<T>(N * 2 - 1, 0);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = A[i];
		}
		for (int i = N - 2; i >= 0; i--){
			ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
		}
	}
	void eval(int i){
		if (i < N - 1){
			lazy[i * 2 + 1] += lazy[i];
			lazy[i * 2 + 2] += lazy[i];
		}
		ST[i] += lazy[i];
		lazy[i] = 0;
	}
	void range_add(int L, int R, T x, int i, int l, int r){
		eval(i);
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			lazy[i] += x;
			eval(i);
		} else {
			int m = (l + r) / 2;
			range_add(L, R, x, i * 2 + 1, l, m);
			range_add(L, R, x, i * 2 + 2, m, r);
			ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
		}
	}
	void range_add(int L, int R, T x){
		range_add(L, R, x, 0, 0, N);
	}
	T range_max(int L, int R, int i, int l, int r){
		eval(i);
		if (R <= l || r <= L){
			return -INF;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r));
		}
	}
	T range_max(int L, int R){
		return range_max(L, R, 0, 0, N);
	}
	T all(){
		eval(0);
		return ST[0];
	}
};
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    cin >> B[i];
  }
  vector<int> T(M), C(M);
  for (int i = 0; i < M; i++){
    cin >> T[i] >> C[i];
  }
  vector<vector<int>> C2(2);
  for (int i = 0; i < M; i++){
    C2[T[i]].push_back(C[i]);
  }
  for (int i = 0; i < 2; i++){
    sort(C2[i].begin(), C2[i].end());
  }
  int H = C2[0].size() + 1;
  int W = C2[1].size() + 1;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++){
    x[i] = lower_bound(C2[0].begin(), C2[0].end(), A[i]) - C2[0].begin();
    y[i] = lower_bound(C2[1].begin(), C2[1].end(), B[i]) - C2[1].begin();
  }
  vector<vector<int>> add(H);
  for (int i = 0; i < N; i++){
    add[x[i]].push_back(y[i]);
  }
  vector<int> a(W);
  for (int i = 0; i < W; i++){
    a[i] = -(W - 1 - i);
  }
  lazy_segment_tree<int> ST(a);
  int ans = 0;
  for (int i = H - 1; i >= 0; i--){
    for (int j : add[i]){
      ST.range_add(0, j + 1, 1);
    }
    ans = max(ans, ST.all());
    ST.range_add(0, W, -1);
  }
  cout << ans << endl;
}
0