社区讨论

可爱妹子刚学 OI,WA 60 求 hack

P11289【MX-S6-T1】「KDOI-11」打印参与者 9已保存回复 12

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
12 条
当前快照
1 份
快照标识符
@mhk70lvf
此快照首次捕获于
2025/11/04 14:33
4 个月前
此快照最后确认于
2025/11/04 23:32
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int N = 2e5 + 10;
namespace FastIO {
	char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p1 = buf, p2 = (p1 + fread(buf, 1, 1 << 21, stdin))) == p1 ? EOF : *p1++)
	template <typename T> inline T read() { T x = 0, w = 0; char ch = getchar(); while (ch < '0' || ch > '9') w |= (ch == '-'), ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar(); return w ? -x : x; }
	template <typename T> inline void write(T x) { if (!x) return; write<T>(x / 10), putchar((x % 10) ^ '0'); }
	template <typename T> inline void print(T x) { if (x > 0) write<T>(x); else if (x < 0) putchar('-'), write<T>(-x); else putchar('0'); }
	template <typename T> inline void print(T x, char en) { print<T>(x), putchar(en); }
}; using namespace FastIO;
namespace solution
{
    typedef pair<int,int> PII; // time,number
    struct ASK
    {
        int s,t,num;
        bool operator<(const ASK &a)const{
            return t < a.t;
        }
    };
    vector <ASK> ask;
    vector <int> ans[N];
    priority_queue <PII,vector<PII>,greater<PII> > wait,release;
    int n,m;
    int tot = 0;
    void solve()
    {
        n = read<int>(),m = read<int>();
        for(int i=1;i<=n;i++) {int s,t; s = read<int>(),t = read<int>();ask.push_back({s,t,i});}
        for(int i=1;i<=m;i++) release.push(PII(i,0));
        sort(ask.begin(),ask.end());
        for(auto [s,t,num]:ask)
        {
            while(wait.size() && wait.top().first <= t){release.push(PII(wait.top().second,wait.top().first));wait.pop();}
            if(!release.size()) {release.push(PII(wait.top().second,t + s));}
            ans[release.top().first].push_back(num);
            auto tt = release.top().second;
            tt = max(release.top().second,t) + s;
            tot ++;
            if(tot >= n) break;
            if(tt > ask[tot].t) {wait.push(PII(tt,release.top().first));release.pop();}
        }
        for(int i=1;i<=m;i++) sort(ans[i].begin(),ans[i].end());
        for(int i=1;i<=m;i++) {print(ans[i].size(),' ');for(auto t:ans[i])print(t,' '); puts("");}
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solution::solve();
    return 0;
}

回复

12 条回复,欢迎继续交流。

正在加载回复...