Submission #51772

# Submission time Handle Problem Language Result Execution time Memory
51772 2018-06-21T05:11:15 Z model_code Sushi (JOI16_sushi) C++17
100 / 100
8564 ms 76036 KB
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define SIZE 650
int dat[400000];
priority_queue<int>que[650];
priority_queue<int>fl[650];
void resolve(int t)
{
	for(int i=0;i<que[t].size();i++)
	{
		fl[t].push(-dat[i+SIZE*t]);
		dat[i+SIZE*t]=-fl[t].top();
		fl[t].pop();
	}
	for(;;)
	{
		if(fl[t].empty())break;
		fl[t].pop();
	}
}
void remake(int t)
{
	int s=que[t].size();
	for(int i=0;i<s;i++)que[t].pop();
	for(int i=0;i<s;i++)que[t].push(dat[SIZE*t+i]);
}
int main()
{
	int num,query;
	scanf("%d%d",&num,&query);
	for(int i=0;i<num;i++)scanf("%d",&dat[i]);
	for(int i=0;i<num;i++)que[i/SIZE].push(dat[i]);
	int NB=(num+SIZE-1)/SIZE;
	for(int p=0;p<query;p++)
	{
		int za,zb,zc;
		scanf("%d%d%d",&za,&zb,&zc);
		za--;
		zb--;
		resolve(za/SIZE);
		resolve(zb/SIZE);
		//for(int i=0;i<num;i++)printf("%d ",dat[i]);printf("\n");
		if(za/SIZE==zb/SIZE&&za<=zb)
		{
			for(int i=za;i<=zb;i++)
			{
				if(dat[i]>zc)swap(dat[i],zc);
			}
			printf("%d\n",zc);
		}
		else
		{
			for(int i=za%SIZE;i<que[za/SIZE].size();i++)
			{
				if(dat[i+SIZE*(za/SIZE)]>zc)swap(dat[i+SIZE*(za/SIZE)],zc);
			}
			int t=(za/SIZE+1)%NB;
			//printf("****%d\n",zc);
			if(t!=zb/SIZE)
			{
				for(;;)
				{
			//printf("****%d %d\n",zc,t);
					que[t].push(zc);
					fl[t].push(-zc);
					zc=que[t].top();
					que[t].pop();
					t++;
					if(t==NB)t-=NB;
					if(t==zb/SIZE)break;
				}
			}
			//printf("****%d\n",zc);
			for(int i=0;i<=zb%SIZE;i++)
			{
				if(dat[i+SIZE*(zb/SIZE)]>zc)swap(dat[i+SIZE*(zb/SIZE)],zc);
			}
			printf("%d\n",zc);
		}
		remake(za/SIZE);
		remake(zb/SIZE);
	}
}

Compilation message

telegraph.cpp: In function 'void resolve(int)':
telegraph.cpp:12:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<que[t].size();i++)
              ~^~~~~~~~~~~~~~
telegraph.cpp: In function 'int main()':
telegraph.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=za%SIZE;i<que[za/SIZE].size();i++)
                      ~^~~~~~~~~~~~~~~~~~~~
telegraph.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&num,&query);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
telegraph.cpp:34:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<num;i++)scanf("%d",&dat[i]);
                        ~~~~~^~~~~~~~~~~~~~
telegraph.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&za,&zb,&zc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 289 ms 504 KB Output is correct
2 Correct 246 ms 504 KB Output is correct
3 Correct 254 ms 556 KB Output is correct
4 Correct 237 ms 604 KB Output is correct
5 Correct 251 ms 732 KB Output is correct
6 Correct 313 ms 732 KB Output is correct
7 Correct 114 ms 732 KB Output is correct
8 Correct 113 ms 732 KB Output is correct
9 Correct 276 ms 732 KB Output is correct
10 Correct 264 ms 732 KB Output is correct
11 Correct 296 ms 748 KB Output is correct
12 Correct 279 ms 748 KB Output is correct
13 Correct 260 ms 760 KB Output is correct
14 Correct 252 ms 892 KB Output is correct
15 Correct 265 ms 892 KB Output is correct
16 Correct 244 ms 892 KB Output is correct
17 Correct 2 ms 892 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 2 ms 892 KB Output is correct
20 Correct 2 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5585 ms 75788 KB Output is correct
2 Correct 5819 ms 75788 KB Output is correct
3 Correct 2370 ms 75788 KB Output is correct
4 Correct 5712 ms 75828 KB Output is correct
5 Correct 4584 ms 75884 KB Output is correct
6 Correct 6122 ms 76036 KB Output is correct
7 Correct 5614 ms 76036 KB Output is correct
8 Correct 5863 ms 76036 KB Output is correct
9 Correct 2423 ms 76036 KB Output is correct
10 Correct 4838 ms 76036 KB Output is correct
11 Correct 2391 ms 76036 KB Output is correct
12 Correct 4693 ms 76036 KB Output is correct
13 Correct 5651 ms 76036 KB Output is correct
14 Correct 5968 ms 76036 KB Output is correct
15 Correct 3282 ms 76036 KB Output is correct
16 Correct 6392 ms 76036 KB Output is correct
17 Correct 4427 ms 76036 KB Output is correct
18 Correct 5739 ms 76036 KB Output is correct
19 Correct 5418 ms 76036 KB Output is correct
20 Correct 5639 ms 76036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 504 KB Output is correct
2 Correct 246 ms 504 KB Output is correct
3 Correct 254 ms 556 KB Output is correct
4 Correct 237 ms 604 KB Output is correct
5 Correct 251 ms 732 KB Output is correct
6 Correct 313 ms 732 KB Output is correct
7 Correct 114 ms 732 KB Output is correct
8 Correct 113 ms 732 KB Output is correct
9 Correct 276 ms 732 KB Output is correct
10 Correct 264 ms 732 KB Output is correct
11 Correct 296 ms 748 KB Output is correct
12 Correct 279 ms 748 KB Output is correct
13 Correct 260 ms 760 KB Output is correct
14 Correct 252 ms 892 KB Output is correct
15 Correct 265 ms 892 KB Output is correct
16 Correct 244 ms 892 KB Output is correct
17 Correct 2 ms 892 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 2 ms 892 KB Output is correct
20 Correct 2 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 5585 ms 75788 KB Output is correct
24 Correct 5819 ms 75788 KB Output is correct
25 Correct 2370 ms 75788 KB Output is correct
26 Correct 5712 ms 75828 KB Output is correct
27 Correct 4584 ms 75884 KB Output is correct
28 Correct 6122 ms 76036 KB Output is correct
29 Correct 5614 ms 76036 KB Output is correct
30 Correct 5863 ms 76036 KB Output is correct
31 Correct 2423 ms 76036 KB Output is correct
32 Correct 4838 ms 76036 KB Output is correct
33 Correct 2391 ms 76036 KB Output is correct
34 Correct 4693 ms 76036 KB Output is correct
35 Correct 5651 ms 76036 KB Output is correct
36 Correct 5968 ms 76036 KB Output is correct
37 Correct 3282 ms 76036 KB Output is correct
38 Correct 6392 ms 76036 KB Output is correct
39 Correct 4427 ms 76036 KB Output is correct
40 Correct 5739 ms 76036 KB Output is correct
41 Correct 5418 ms 76036 KB Output is correct
42 Correct 5639 ms 76036 KB Output is correct
43 Correct 6160 ms 76036 KB Output is correct
44 Correct 5756 ms 76036 KB Output is correct
45 Correct 3917 ms 76036 KB Output is correct
46 Correct 6327 ms 76036 KB Output is correct
47 Correct 6599 ms 76036 KB Output is correct
48 Correct 6003 ms 76036 KB Output is correct
49 Correct 7086 ms 76036 KB Output is correct
50 Correct 6595 ms 76036 KB Output is correct
51 Correct 6193 ms 76036 KB Output is correct
52 Correct 7356 ms 76036 KB Output is correct
53 Correct 7316 ms 76036 KB Output is correct
54 Correct 7160 ms 76036 KB Output is correct
55 Correct 7779 ms 76036 KB Output is correct
56 Correct 7709 ms 76036 KB Output is correct
57 Correct 7909 ms 76036 KB Output is correct
58 Correct 5323 ms 76036 KB Output is correct
59 Correct 4561 ms 76036 KB Output is correct
60 Correct 4780 ms 76036 KB Output is correct
61 Correct 5693 ms 76036 KB Output is correct
62 Correct 5674 ms 76036 KB Output is correct
63 Correct 6291 ms 76036 KB Output is correct
64 Correct 2560 ms 76036 KB Output is correct
65 Correct 3910 ms 76036 KB Output is correct
66 Correct 4800 ms 76036 KB Output is correct
67 Correct 6226 ms 76036 KB Output is correct
68 Correct 7867 ms 76036 KB Output is correct
69 Correct 8460 ms 76036 KB Output is correct
70 Correct 8564 ms 76036 KB Output is correct