求大佬解惑

有没有哪一位大佬可以解答一下,样例过了,自测也能过,但是为啥提交却爆零?

#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
#include <set>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
using namespace std;
typedef long long ll;
const int MAXN = 1e4;
const int MOD = 1e9;
multiset<int> mt;
multiset<int>::iterator it;
int main()
{
    ios;
    int n, k;;
    cin >> n >> k;
    while (n--) {
        string sh;
        int t;
        cin >> sh >> t;
        it = mt.lower_bound(t - k);
        if (sh == "add") {
            if (mt.empty() || it != mt.end() && abs(*it - t) > k)  mt.insert(t);
        }
        else if(sh=="query"){
            if (it == mt.end() || abs(*it - t) > k) cout << "No" << '\n';
            else cout << "Yes" << '\n';
        }
        else {
            while (it != mt.end() && abs(*it - t) <= k) {
                mt.erase(it);
                it = mt.lower_bound(t - k);
            }
        }
    }
    return 0;
}
全部评论
你第 30 行的条件有问题。 第 30 行和第 33 行的逻辑应该是一致的。
点赞 回复
分享
发布于 2020-05-29 12:44

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务