why TLE on #10
查看原帖
why TLE on #10
1219662
wwxxbb楼主2024/8/29 21:26
#include <bits/stdc++.h>
using namespace std;

namespace IO {
	const int SZ = 1 << 18; static char *p1, *p2, buf[SZ];
	#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, SZ, stdin), p1 == p2) ? EOF : *p1++)
	inline void skip() {for (char ch = getchar(); ch == ' ' || ch == '\n' || ch == '\t'; ch = getchar());}
	int t; char ch;
	template <typename T> inline void read(T& x) {x = 0, t = 1, ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') t = -1; for (; '0' <= ch && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); x *= t;}
	inline void read(char& x) {skip(), x = getchar();}
	template <typename T, typename... Args> inline void read(T& t, Args&... args) {read(t); read(args...);}
	template <typename It> inline void read(const It& begin, const It& end) {for (It it = begin; it != end; it++) read(*it);}
	template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; static int st[40]; int top = 0; do {st[top++] = x % 10, x /= 10;} while (x); while (top) putchar(st[--top] ^ 48);}
	template <typename T> inline void write(const char c, const T x) {write(x), putchar(c);}
	template <typename T, typename... Args> inline void write(T t, const char c, Args... args) {write(c, t); write(c, args...);}
	template <typename T> inline void writeln(const T x) {write(x), putchar('\n');}
	template <typename T> inline void writesp(const T x) {write(x), putchar(' ');}
	template <typename It> inline void write(const char c, const It& begin, const It& end) {for (It it = begin; it != end; it++) write(*it), putchar(c);}
} using namespace IO;

const int N = 1000010;

int n, k, a[N], cnt, ans;
bitset<N> st;

inline void clear() {
    for (int i = 0; i < k; i ++) st[i] = 0;
    cnt = 0;
}

int main() {
    read(n, k); k = min(k, n + 1);
    for (int i = 1, x; i <= n; i ++) {
        read(x); a[i] = x;
        if (x == k) { clear(); continue; }
        if (x < k && !st[x]) {
            st[x] = 1;
            ++ cnt;
        }
        if (cnt == k) {
            ++ ans;
            a[i] = k;
            clear();
        }
    }
    writeln(ans);
    for (int i = 1; i <= n; i ++)
        writesp(a[i]);
    return 0;
}
2024/8/29 21:26
加载中...