QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19112#1877. Matryoshka Dolls_siri_Compile Error//C1.6kb2022-01-28 10:45:222022-05-18 04:05:39

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 04:05:39]
  • 评测
  • [2022-01-28 10:45:22]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

struct section
{
	int l, r, num;
};

int n, m, l, r, i, len, a[500001], f[500001], b[500001], ans[500001]; 
section sec[500001];
set < int > s;

int abs(int x)
{
	return x > 0 ? x : -x;
}

bool cmp(section l, section r)
{
	return b[l.l] ^ b[r.l] ? l.l < r.l : (b[l.l] & 1 ? l.r < r.r : l.r > r.r);
}

void move(int pos1, int opt)
{
	if (opt > 0)
		s.insert(a[pos1]);
		
	set < int >::iterator pos, end, last, next;
	
	pos = s.find(a[pos1]);
	end = s.end();
	
	if (pos != s.begin())
	{
		last = --pos;
		pos++;
	}
	
	if (pos != --end)
	{
		next = ++pos;
		pos--;
	}
	
	if (pos == s.begin())
		ans[i] += abs(f[*next] - f[*pos]) * opt;
	
	else if (pos == end)
		ans[i] += abs(f[*last] - f[*pos]) * opt;	
	
	else
		ans[i] += (abs(f[*next] - f[*pos]) + abs(f[*pos] - f[*last]) - abs(f[*last] - f[*next])) * opt;
	
	if (opt < 0)
		s.erase(pos);	
	
}


int main()
{

	scanf("%d%d", &n, &m);
	
	len = sqrt(n);
	
	for(i = 1; i <= n; i++)
	{
		scanf("%d", a + i);
		f[a[i]] = i;
		b[i] = (i - 1) / len;
	}
	
	for(i = 1; i <= m; sec[i].num = i, i++)	
		scanf("%d%d", &sec[i].l, &sec[i].r);
		
	sort(sec + 1, sec + m + 1, cmp);
	
	l = 1;
	r = 1;
	
	s.insert(a[1]);
	
	for (i = 1; i <= m; i++)
	{
		ans[i] = ans[i - 1];
		
		while (l > sec[i].l)
			move(--l, 1);
			
		while (r < sec[i].r)
			move(++r, 1);
			
		while (l < sec[i].l)
			move(l++, -1);		
		
		while (r > sec[i].r)
			move(r--, -1);
	}
	
	for (i = 1; i <= m; i++)
		printf("%d\n", ans[sec[i].num]);
}

Details

answer.code:1:10: fatal error: cstdio: No such file or directory
 #include <cstdio>
          ^~~~~~~~
compilation terminated.