1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| #include <iostream> #include <cstdio> #include <cstring>
#define lson root << 1 #define rson root << 1 | 1
using namespace std;
const int MAXN = 15e05 + 10;
int N, Q, P, m; int ori[MAXN]= {0};
struct node { int a[6], cnt[6], n; void init () { memset (a, 0, sizeof (a)); memset (cnt, 0, sizeof (cnt)); n = 0; } void operator = (const node& p) { n = p.n; memcpy (a, p.a, sizeof (a)); memcpy (cnt, p.cnt, sizeof (cnt)); } node operator + (const node& p) const { node ret = p; for (int i = 1; i <= n; i ++) { bool in = false; for (int j = 1; j <= ret.n; j ++) if (a[i] == ret.a[j]) { ret.cnt[j] += cnt[i]; in = true; break; } if (in) continue; if (ret.n < m) { ret.a[++ ret.n] = a[i]; ret.cnt[ret.n] = cnt[i]; continue; } int k = 0; for (int j = 1; j <= ret.n; j ++) if (k == 0 || ret.cnt[j] < ret.cnt[k]) k = j; if (ret.cnt[k] > cnt[i]) { for (int j = 1; j <= ret.n; j ++) ret.cnt[j] -= cnt[i]; } else { int tp = ret.cnt[k]; ret.a[k] = a[i]; ret.cnt[k] = cnt[i] - ret.cnt[k]; for (int j = 1; j <= ret.n; j ++) if (j != k) ret.cnt[j] -= tp; } } return ret; } } ; node T[MAXN << 2]; int lazy[MAXN << 2]= {0}; inline void setup (int root, int left, int right, int x) { T[root].a[T[root].n = 1] = x; T[root].cnt[1] = right - left + 1; } void build (int root, int left, int right) { T[root].init (); if (left == right) { setup (root, left, right, ori[left]); return ; } int mid = (left + right) >> 1; build (lson, left, mid); build (rson, mid + 1, right); T[root] = T[lson] + T[rson]; } inline void pushdown (int root, int left, int right) { if (! lazy[root]) return ; int mid = (left + right) >> 1; setup (lson, left, mid, lazy[root]); setup (rson, mid + 1, right, lazy[root]); lazy[lson] = lazy[rson] = lazy[root]; lazy[root] = 0; } void modify (int root, int left, int right, int L, int R, int x) { if (L <= left && right <= R) { setup (root, left, right, x); lazy[root] = x; return ; } pushdown (root, left, right); int mid = (left + right) >> 1; if (L <= mid) modify (lson, left, mid, L, R, x); if (R > mid) modify (rson, mid + 1, right, L, R, x); T[root] = T[lson] + T[rson]; } node query (int root, int left, int right, int L, int R) { if (L <= left && right <= R) return T[root]; pushdown (root, left, right); int mid = (left + right) >> 1; node ret; ret.init (); if (L <= mid) ret = ret + query (lson, left, mid, L, R); if (R > mid) ret = ret + query (rson, mid + 1, right, L, R); return ret; }
inline int getnum () { int num = 0; char ch = getchar (); while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar (); return num; }
int main () { N = getnum (), Q = getnum (), P = getnum (); m = 100 / P; for (int i = 1; i <= N; i ++) ori[i] = getnum (); build (1, 1, N); for (int q = 1; q <= Q; q ++) { int type = getnum (); if (type == 1) { int l = getnum (), r = getnum (), id = getnum (); modify (1, 1, N, l, r, id); } else { int l = getnum (), r = getnum (); node ans = query (1, 1, N, l, r); printf ("%d", ans.n); for (int i = 1; i <= ans.n; i ++) printf (" %d", ans.a[i]); puts (""); } }
return 0; }
|