Exemple #1
0
void init() {
  a[n + 1] = 0;
  st = 0;
  stack[++st] = n + 1;

  for (int i = n; i >= 1; --i) {
    nrdr[i] = query_stack(a[i] - 1) - i;
    insert_stack(a[i], i);
  }

  a[0] = INF;
  st = 0;
  stack[++st] = 0;
  
  for (int i = 1; i <= n; ++i) {
    nrst[i] = i - query_stack(a[i]);
    insert_stack(a[i], i);
  }

  for (int i = 1; i <= n; ++i)
    sum[a[i]] += 1LL * nrst[i] * nrdr[i];

  for (int i = 1; i < N; ++i)
    sum[i] += sum[i - 1]; 
}
Exemple #2
0
void query_tree(FILE *rsp)
{
	fprintf(rsp, "{");
	fprintf(rsp, "\"focusedMonitorId\":%u,", mon->id);
	if (pri_mon != NULL) {
		fprintf(rsp, "\"primaryMonitorId\":%u,", pri_mon->id);
	}
	fprintf(rsp, "\"clientsCount\":%i,", clients_count);
	fprintf(rsp, "\"monitors\":");
	fprintf(rsp, "[");
	for (monitor_t *m = mon_head; m != NULL; m = m->next) {
		query_monitor(m, rsp);
		if (m->next != NULL) {
			fprintf(rsp, ",");
		}
	}
	fprintf(rsp, "]");
	fprintf(rsp,",");
	fprintf(rsp, "\"focusHistory\":");
	query_history(rsp);
	fprintf(rsp,",");
	fprintf(rsp, "\"stackingList\":");
	query_stack(rsp);
	fprintf(rsp, "}");

}