Http://codeforces.com/problemset/problem/755/D
Each time a new diagonal line is drawn, consider crossing a few of the existing diagonal lines.
You can use the tree array interval to modify the point query to maintain the vertices of the polygon. Each time the answer increases the left end of the new diagonal in how many intervals + the right end point within the number of intervals + 1, each time the new picture of the diagonal coverage of the smaller interval within the interior of each dot plus 1. Note that it must be a smaller interval, as this will ensure that the left and right endpoints are not in the same interval and do not repeat statistics.
#include <cstdio> #include <algorithm>using namespace std;typedef long long ll;int n,m;ll ans=1ll;int d[ 1000010];int Query (int p) {int res=0; for (;p; p-= (p& (P))) res+=d[p]; return res;} void Add (int p,int v) {for (;p <=n;p+= (p& (-P)) d[p]+=v;} void Update (int l,int r) {if (l<r) { if (l+1==r) return; Add (l+1,1); if (r<=n) Add (r,-1); } else { if (l<n) Add (l,1); Add (+); Add (r,-1);} } int main () {//freopen ("d.in", "R", stdin), scanf ("%d%d", &n,&m), if (M>N/2) m=n-m;int u=1;for (int i=1;i <=n;++i) { int pre=u; u+=m; if (u>n) u-=n; ans+= ((ll) query (pre)), ans+= ((ll) query (U) +1ll); Update (pre,u); printf ("%i64d%c", ans,i==n? ' \ n ': '); } return 0;}
"Tree array" Codeforces Round #755 D. Polandball and Polygon