社区讨论
TLE #7求卡常
P7603[THUPC 2021] 鬼街参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhj3hkn2
- 此快照首次捕获于
- 2025/11/03 20:07 4 个月前
- 此快照最后确认于
- 2025/11/03 20:07 4 个月前
CPP
#include <bits/stdc++.h>
#define int long long
namespace my_std{
#define one_case int tt = 1; while(tt--)
#define multi_case int tt; cin>>tt; while(tt--)
#define fir(i,a,b) for(int i=(a);i<=(b);++i)
#define rif(i,a,b) for(int i=(a);i>=(b);++i)
#define For(i,a,b) for(auto i=(a);i!=(b);++i)
using LL = long long;
const int Mod = 1e9+7;
template<class T> void qmod(T &x){ x = x<0 ? x+Mod : (x>=Mod ? x-Mod : x); }
template<class T> T Qmod(T x){ return x<0 ? x+Mod : (x>=Mod ? x-Mod : x); }
using lf = double;
const double eps = 1e-10;
using pii = std::pair<int,int>;
template<class T1,class T2> auto cp(T1 x,T2 y){
return std::make_pair(x,y);
}
template<class T1,class T2> std::istream & operator >> (std::istream &in, std::pair<T1,T2> &A){
in >> A.first >> A.second;
return in;
}
template<class T1,class T2> std::ostream & operator << (std::ostream &ot, std::pair<T1,T2> &A){
ot << "(" << A.first << "," << A.second <<")";
return ot;
}
// my vector operator
using vi = std::vector<int>;
template<class T> std::istream & operator >> (std::istream &in,std::vector<T> &A){
size_t Size = A.size();
For(i,1,Size){
in >> A[i];
}
return in;
}
template<class T> std::ostream & operator << (std::ostream &ot,std::vector<T> &A){
size_t Size = A.size();
For(i,0,Size){
ot << A[i]; ot << (i!=Size-1 ? "," : "");
}
return ot;
}
template<class T> T Abs(T x){
return x>0 ? x : -x;
}
template<class T> T ceil_except(T x,T y){
return (x/y*y == x) ? x/y : x/y+1;
}
template<class T> class PQ{
private:
std::priority_queue< T,std::vector<T>,std::greater<T> > q1;
std::priority_queue< T,std::vector<T>,std::greater<T> > q2;
public:
void Insert(T x){
q1.push(x);
}
void Delete(T x){
q2.push(x);
}
bool Empty(){
while(!q1.empty() and !q2.empty() and q1.top()==q2.top()){
q1.pop();
q2.pop();
}
return q1.empty();
}
T Top(){
Empty();
return q1.top();
}
};
void Ios(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
template<class ... Args> void Print(Args ... args){
size_t count = 0;
( (std::cerr << (count++ ? "," : "") << args), ...);
}
#ifdef DEBUG
#define DDebug(...) \
cerr << "@" << __func__ << ",#" << __LINE__ << ": ["; \
Print(#__VA_ARGS__); \
cerr << "] = {"; \
Print(__VA_ARGS__); \
cerr << "}\n";
#define ddebug(...) \
"@" << __func__ << ",#" << __LINE__ << ": [" << #__VA_ARGS__ << "] = {" << __VA_ARGS__ << "}"
#else
#define DDebug(...) void(0)
#endif
}using namespace my_std;
using namespace std;
int n,m;
signed main(){
string __name = "std";
if(__name!=""){
freopen((__name+".in").c_str(),"r",stdin);
freopen((__name+".out").c_str(),"w",stdout);
}
one_case[&]{
Ios();
cin >> n >> m;
vi pri_w,pri_v(n+1,0),pri_i(n+1,0);
fir(i,2,n){
if(!pri_v[i]){
pri_i[i] = pri_w.size();
pri_w.emplace_back(i);
}
for(int j = 0; j<pri_w.size() and pri_w[j]*i<=n; ++j){
pri_v[ pri_w[j]*i ] = 1;
if(i%pri_w[j] == 0) break;
}
}
vector<vi> prime(n+1);
fir(i,2,n){
if(!pri_v[i]){
for(int j = 1; j*i<=n; ++j){
prime[j*i].emplace_back(i);
}
}
}
//
vi haunt(n+1,0);
vector<pii> Limit(m+1);
vector< vector<pii> > limits(m+1);
vector< PQ<pii> > q(pri_w.size());
auto Sum = [&](int X){
int js = 0;
for(int &x : prime[X]){
js += haunt[x];
}
return js;
};
auto Down = [&](int I,int X,int y){
for(int &x : prime[X]){
int id = pri_i[x];
limits[I].emplace_back( cp(id,haunt[x]+y) );
q[id].Insert( cp(haunt[x]+y,I) );
}
};
auto Clear = [&](int I){
for(auto &[id,y] : limits[I]){
q[id].Delete( cp(y,I) );
}
limits[I].clear();
};
auto Check = [&](int I){
if(Sum(Limit[I].first) >= Limit[I].second){
return true;
}
return false;
};
vi ans;
auto Modify_and_Query = [&](int X,int y){
vi stk;
for(int &x : prime[X]){
haunt[x] += y;
int id = pri_i[x];
vector<pii> tmp;
while(!q[id].Empty() and q[id].Top().first<=haunt[x]){
tmp.emplace_back(q[id].Top());
stk.emplace_back(tmp.back().second);
q[id].Delete(tmp.back());
}
for(pii &inr : tmp){
q[id].Insert(inr);
}
}
sort(stk.begin(),stk.end());
stk.erase( unique(stk.begin(),stk.end()) , stk.end() );
for(int &I : stk){
int tx = Limit[I].first;
int ty = Limit[I].second-Sum(tx);
Clear(I);
if( Check(I) ){
ans.emplace_back(I);
}else{
Down(I,tx,ceil_except(ty,(int)prime[tx].size()));
}
}
};
vi que_id(m+1,0); int que_ct = 0; int las = 0;
fir(i,1,m){
int op,x,y;
cin >> op >> x >> y;
y = y^las;
if(op==0){
Modify_and_Query(x,y);
sort(ans.begin(),ans.end());
cout << ans.size() << ' ';
for(int anss : ans){
cout << que_id[anss] << ' ';
}
cout << '\n';
las = ans.size();
ans.clear();
}
if(op==1){
que_id[i] = ++que_ct;
if(!y){
ans.emplace_back(i);
}else{
Limit[i] = {x,Sum(x)+y};
Down(i,x,ceil_except(y,(int)prime[x].size()));
}
}
}
}();
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...