Submission #1017225

#TimeUsernameProblemLanguageResultExecution timeMemory
1017225dostsSails (IOI07_sails)C++17
60 / 100
127 ms9048 KiB
//Dost SEFEROĞLU #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define vi vector<int> #define all(xx) xx.begin(),xx.end() const int N = 1e6+1,inf = 2e9,B = 23,MOD = 30013,LIM = 1e9; struct ST { vi t,lazy; ST(int nn) { t.assign(4*nn+1,0); lazy.assign(4*nn+1,0); } void push(int node,bool leaf) { t[node]+=lazy[node]; if (!leaf) { lazy[2*node]+=lazy[node]; lazy[2*node+1]+=lazy[node]; } lazy[node] = 0; } void update(int node,int l,int r,int L,int R,int v) { push(node,l==r); if (l > R || r < L) return; if (l >= L && r <= R) { lazy[node] += v; push(node,l==r); return; } int m = (l+r) >> 1; update(2*node,l,m,L,R,v),update(2*node+1,m+1,r,L,R,v); t[node] = min(t[2*node],t[2*node+1]); } int query(int node,int l,int r,int p) { push(node,l==r); if (l == r) return t[node]; int m = (l+r) >> 1; if (p <= m) return query(2*node,l,m,p); else return query(2*node+1,m+1,r,p); } int walk(int node,int l,int r,int x) { push(node,l==r); if (t[node] >= x) return -1; if (l == r) return l; int m = (l+r) >> 1; int pp = walk(2*node,l,m,x); if (pp != -1) return pp; return walk(2*node+1,m+1,r,x); } int walk2(int node,int l,int r,int x) { push(node,l==r); if (t[node] > x) return -1; if (l == r) return l; int m = (l+r) >> 1; int pp = walk2(2*node,l,m,x); if (pp != -1) return pp; return walk2(2*node+1,m+1,r,x); } int worth(int node,int l,int r) { push(node,l==r); if (l == r) return t[node]*(t[node]-1)/2; int m = (l+r) >> 1; return worth(2*node,l,m)+worth(2*node+1,m+1,r); } }; void solve() { int n; cin >> n; vector<pii> poles(n+1); for (int i=1;i<=n;i++) cin >> poles[i].ff >> poles[i].ss; sort(poles.begin()+1,poles.end()); ST st(n); int curheight = 1; for (int i=1;i<=n;i++) { curheight = poles[i].ff; int x = poles[i].ss; int big = st.query(1,1,n,curheight-x+1); int smbig = st.walk(1,1,n,big); //<big olan ilk yer int firstbig = st.walk2(1,1,n,big); // =big olan ilk yer if (smbig != -1 && smbig <= curheight) st.update(1,1,n,smbig,curheight,1); int rem = x-(curheight-smbig+1); if (smbig == -1 || smbig > curheight) rem = x; st.update(1,1,n,firstbig,firstbig+rem-1,1); } cout << st.worth(1,1,n) << '\n'; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...