QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#530979 | #9228. ICPC Inference | ucup-team159# | WA | 120ms | 150220kb | C++20 | 9.0kb | 2024-08-24 17:50:06 | 2024-08-24 17:50:06 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < (t); ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define newline puts("")
#define vc vector
using namespace std;
template<class T> using vv = vc<vc<T>>;
template<class T> using PQ = priority_queue<T,vc<T>,greater<T>>;
using uint = unsigned; using ull = unsigned long long;
using vi = vc<int>; using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long; using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>;
using P = pair<int,int>; using vp = vc<P>; using vvp = vv<P>; using LP = pair<ll,ll>;
int geti(){int x;scanf("%d",&x);return x;}
vi pm(int n, int s=0) { vi a(n); iota(rng(a),s); return a;}
template<class T1,class T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<class T1,class T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<class T>istream& operator>>(istream&i,vc<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<class T>string join(const T&v,const string&d=""){stringstream s;rep(i,sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<class T>ostream& operator<<(ostream&o,const vc<T>&v){if(sz(v))o<<join(v," ");return o;}
template<class T>void vin(vc<T>&a){int n;cin>>n;a=vc<T>(n);cin>>a;}
template<class T>void vin(vv<T>&a){int n,m;cin>>n>>m;a=vv<T>(n,vc<T>(m));cin>>a;}
template<class T1,class T2>void operator--(pair<T1,T2>&a,int){a.fi--;a.se--;}
template<class T1,class T2>void operator++(pair<T1,T2>&a,int){a.fi++;a.se++;}
template<class T>void operator--(vc<T>&a,int){for(T&x:a)x--;}
template<class T>void operator++(vc<T>&a,int){for(T&x:a)x++;}
template<class T>void operator+=(vc<T>&a,T b){for(T&x:a)x+=b;}
template<class T>void operator-=(vc<T>&a,T b){for(T&x:a)x-=b;}
template<class T>void operator*=(vc<T>&a,T b){for(T&x:a)x*=b;}
template<class T>void operator/=(vc<T>&a,T b){for(T&x:a)x/=b;}
template<class T>void operator+=(vc<T>&a,const vc<T>&b){a.insert(a.end(),rng(b));}
template<class T1,class T2>pair<T1,T2>operator+(const pair<T1,T2>&a,const pair<T1,T2>&b){return {a.fi+b.fi,a.se+b.se};}
template<class T1,class T2>pair<T1,T2>operator-(const pair<T1,T2>&a,const pair<T1,T2>&b){return {a.fi-b.fi,a.se-b.se};}
template<class T>pair<T,T>operator*(const pair<T,T>&a,T b){return {a.fi*b,a.se*b};}
template<class T1,class T2>bool mins(T1& x,const T2&y){if(y<x){x=y;return true;}else return false;}
template<class T1,class T2>bool maxs(T1& x,const T2&y){if(x<y){x=y;return true;}else return false;}
template<class T>T min(const vc<T>&a){return *min_element(rng(a));}
template<class T>T max(const vc<T>&a){return *max_element(rng(a));}
template<class Tx,class Ty>Tx dup(Tx x, Ty y){return (x+y-1)/y;}
template<class T>ll suma(const vc<T>&a){ll s=0;for(auto&&x:a)s+=x;return s;}
template<class T>ll suma(const vv<T>&a){ll s=0;for(auto&&x:a)s+=suma(x);return s;}
template<class T>void uni(T&a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
template<class T>void prepend(vc<T>&a,const T&x){a.insert(a.begin(),x);}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yes { puts("Yes"); return;}
#define no { puts("No"); return;}
#define rtn(x) { cout<<(x)<<'\n'; return;} // flush!
#define yn {puts("Yes");}else{puts("No");}
// Binary Indexed Tree
template<typename T=int>
struct bit {
int n; vector<T> d;
bit() {}
bit(int mx): n(mx+2), d(mx+2) {}
void add(int i, T x=1) {
for (++i;i<n;i+=i&-i) d[i] += x;
}
T sum(int i) {
T x = 0;
for (++i;i;i-=i&-i) x += d[i];
return x;
}
T sum(int l, int r) { return sum(r-1)-sum(l-1);}
};
//
const int M = 200025;
const int M2 = M*2;
const int M3 = M*3;
const int X = 20;
struct RG {
int l, r;
RG(int l=0, int r=0):l(l),r(r) {}
bool operator<(const RG& _) const { return l<_.l;}
};
istream& operator>>(istream&i,RG&a){return i>>a.l>>a.r;}
ostream& operator<<(ostream&o,const RG&a){return o<<a.l<<" "<<a.r;}
struct SM {
int l, n, w;
SM(int l=0, int n=0, int w=0):l(l),n(n),w(w) {}
bool operator<(const SM& _) const { return l<_.l;}
};
istream& operator>>(istream&i,SM&a){return i>>a.l>>a.n>>a.w;}
ostream& operator<<(ostream&o,const SM&a){return o<<a.l<<" "<<a.n<<" "<<a.w;}
ll p3(ll n) {
return n*(n-1)*(n-2);
}
struct Solver {
void solve() {
int n,m;
scanf("%d%d%*d",&m,&n);
vvi subs(n);
rep(i,m) {
int a,t;
scanf("%d%d",&a,&t);
--a;
subs[a].pb(t);
}
sort(rng(subs), [&](vi& a, vi& b) { return sz(a) > sz(b);});
while (sz(subs) && sz(subs.back()) == 0) subs.pob();
n = sz(subs);
vi L(n), R(n);
vv<RG> gaps(n);
vv<SM> sms(n);
rep(i,n) {
vi& s = subs[i];
int w = sz(s);
R[i] = min(M3-3, M2+s.back()+20*(w-1));
if (w == 1) L[i] = M2+s[0];
else if (w == 2) L[i] = s[0]+s[1];
else L[i] = 1;
vc<RG> rgs;
if (w >= 2) {
int two = min(M2-2, s.back() + s.end()[-2] + 20*(w-2));
rgs.eb(two,two);
}
rep(i,w) rgs.eb(M2+s[i], M2+s[i]+20*i);
vc<RG> wa;
vv<RG> grs;
for (auto [l,r] : rgs) {
if (sz(wa) && l <= wa.back().r) maxs(wa.back().r, r), grs.back().eb(l,r);
else wa.eb(l,r), grs.pb(vc<RG>(1,RG(l,r)));
}
int pre = 0;
for (auto [l,r] : wa) {
if (pre < l) gaps[i].eb(pre,l);
pre = r+1;
}
if (pre < M3-2) gaps[i].eb(pre,M3-2);
for (auto& gr : grs) {
vp evs;
for (auto [l,r] : gr) {
evs.eb(l,1);
evs.eb(r,-1);
}
sort(rng(evs));
vi cnt(20);
int pre = -1;
for (auto [x,a] : evs) {
int p = x%20;
if (pre != -1 && pre != x) {
int sp = pre%20;
if (cnt[sp] == 0) {
int np = sp, w = 0;
while (!cnt[np]) np = (np+1)%20, w++;
sms[i].eb(pre,1,w);
pre += w;
}
int nr = x-(x-pre)%20;
if (pre < nr) {
int np = sp, w = 0, pl = pre;
int num = (nr-pre)/20;
rep(j,20) {
np = (np+1)%20; w++;
if (cnt[np]) {
sms[i].eb(pl,num,w);
pl += w; w = 0;
}
}
}
if (nr < x) {
sms[i].eb(nr,1,x-nr);
}
}
cnt[p] += a;
pre = x;
}
}
}
vi sL(M3+1), sR(M3+1), sLR(M3+1);
rep(i,n) sL[L[i]+1]++;
rep(i,n) sR[R[i]+1]++;
rep(i,n) if (L[i] == R[i]) sLR[R[i]+1]++;
rep(i,M3) sL[i+1] += sL[i];
rep(i,M3) sR[i+1] += sR[i];
rep(i,M3) sLR[i+1] += sLR[i];
vvl sS(20, vl(M3+1));
rep(w,20) {
rep(i,M3-w) {
int r = i+w;
ll now = ll(sL[r]-sL[i])*(sR[r]-sR[i]);
now -= sLR[r]-sLR[i];
sS[w][i] = now;
}
rep(i,M3-20) sS[w][i+20] += sS[w][i];
}
ll ans = 0;
ll ans1 = [&]{
ll res = 0;
rep(i,n) {
for (auto [l,r] : gaps[i]) {
ll now = ll(sL[r]-sL[l])*(sR[r]-sR[l]);
now -= sLR[r]-sLR[l];
res += now;
}
}
return res;
}();
ll ans2 = [&]{
ll res = 0;
rep(i,n) {
for (auto [l,num,w] : sms[i]) {
l -= 20; int r = l+num*w;
if (l >= M3-22) continue;
if (r >= M3-2) {
r -= (r-(M3-2))/20*20;
}
ll now = 0;
w--;
if (r >= 0) now += sS[w][r];
if (l >= 0) now -= sS[w][l];
res += now;
}
}
return res;
}();
ll ans3 = [&]{
ll res = 0;
vvi ls(M3);
vvi qls(M3);
rep(i,n) {
if (L[i] < R[i]) ls[R[i]].pb(L[i]);
for (auto [l,r] : gaps[i]) qls[r].pb(l);
}
bit d(M3); int tot = 0;
rep(x,M3) {
for (int l : qls[x]) res += tot-d.sum(l-1);
for (int l : ls[x]) d.add(l), tot++;
}
return res;
}();
ll ans4 = [&]{
ll res = 0;
vi ls = L, rs = R;
sort(rng(ls));
sort(rng(rs));
int i = 0;
for (int l : ls) {
while (i < n && rs[i] < l) i++;
res += i;
}
return res;
}();
ans = ans1+ans2-ans3+ans4;
// cerr<<ans1<<" "<<ans2<<" "<<ans3<<" "<<ans4<<endl;
ans = p3(n) - ans;
cout<<ans<<endl;
}
};
int main() {
// cin.tie(nullptr); ios::sync_with_stdio(false);
int ts = 1;
// scanf("%d",&ts);
rep1(ti,ts) {
Solver solver;
solver.solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 27ms
memory: 134504kb
input:
4 3 300 1 10 2 25 2 30 3 50
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 36ms
memory: 134492kb
input:
4 6 200000 6 1 6 1 1 2 2 2
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: -100
Wrong Answer
time: 120ms
memory: 150220kb
input:
191580 64997 56 24878 1 35060 1 24245 1 64330 1 9650 1 15423 1 34953 1 21456 1 36718 1 21395 1 17613 1 16995 1 45257 1 31277 1 20026 1 1870 1 25581 1 9997 1 54701 1 30752 1 32269 1 705 1 64186 1 58881 1 24614 1 55311 1 18259 1 58886 1 23296 1 17628 1 3411 1 37469 1 47951 1 12188 1 60720 1 54168 1 45...
output:
274536840492551
result:
wrong answer 1st numbers differ - expected: '274533940012863', found: '274536840492551'