Submission #411241

# Submission time Handle Problem Language Result Execution time Memory
411241 2021-05-24T19:31:50 Z Jasiekstrz Sails (IOI07_sails) C++17
60 / 100
26 ms 4664 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 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 2152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 4616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3280 KB Output is correct
2 Correct 25 ms 4664 KB Output is correct