Submission #411242

# Submission time Handle Problem Language Result Execution time Memory
411242 2021-05-24T19:38:38 Z Jasiekstrz Sails (IOI07_sails) C++17
100 / 100
34 ms 4200 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5;
struct Interval
{
	int l,r;
	long long cnt;
	bool operator<(const Interval &oth)
	{
		return (cnt/(r-l+1))<((oth.cnt+oth.r-oth.l)/(oth.r-oth.l+1));
	}
	void operator+=(const Interval &oth)
	{
		l=oth.l;
		cnt+=oth.cnt;
		return;
	}
};
int t[N+10][2];
int r[N+10];
vector<Interval> st;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i][0]>>t[i][1];
		r[t[i][0]-t[i][1]+1]++;
		r[t[i][0]+1]--;
	}
	for(int i=1;i<=N;i++)
	{
		r[i]+=r[i-1];
		Interval tmp={i,i,r[i]};
		while(!st.empty() && st.back()<tmp)
		{
			tmp+=st.back();
			st.pop_back();
		}
		st.push_back(tmp);
	}
	long long ans=0;
	for(auto v:st)
	{
		for(int i=v.l;i<=v.r;i++)
		{
			long long tmp=(v.cnt/(v.r-i+1));
			v.cnt-=tmp;
			ans+=tmp*(tmp-1)/2;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 2760 KB Output is correct
2 Correct 4 ms 2760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2760 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2760 KB Output is correct
2 Correct 4 ms 2760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2760 KB Output is correct
2 Correct 4 ms 2760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2760 KB Output is correct
2 Correct 4 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2888 KB Output is correct
2 Correct 10 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1500 KB Output is correct
2 Correct 23 ms 2760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3476 KB Output is correct
2 Correct 29 ms 4200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2032 KB Output is correct
2 Correct 24 ms 3656 KB Output is correct