为啥写puts("Nothing")就过不了
  • 板块CF69E Subsegments
  • 楼主xinruian
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/23 13:10
  • 上次更新2023/11/23 13:15:32
查看原帖
为啥写puts("Nothing")就过不了
832996
xinruian楼主2023/11/23 13:10

代码如下,把cout改成puts就不行

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>

using namespace std;

const int N = 1e5 + 10;
int a[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k;
	unordered_map<int, int> mp;
	set<int, greater<int>> st; 
	cin >> n >> k;
	
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		int j = a[i];
		++ mp[j];
		if (mp[j] == 1)	st.insert(j);
		if (mp[j] == 2)	st.erase(j);
		
		if (i < k)	continue;
		if (st.empty())
			cout << "Nothing" << endl;
      	 // puts("Nothing"); 这样写就错了
		else
			cout << *st.begin() << endl;
		
		int x = a[i - k + 1];
		-- mp[x];
		if (mp[x] == 1)
			st.insert(x);
		else if (mp[x] == 0)
			st.erase(x);			
	}
	
	return 0;
}

错误样例(我本地调试样例是正确的啊,到cf就错了?)

Input
6 4
3
3
3
4
4
2
Output
4
3
Nothing
Answer
4
Nothing
3
2023/11/23 13:10
加载中...