# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
56033 |
2018-07-09T12:12:57 Z |
정원준(#2100) |
Sushi (JOI16_sushi) |
C++11 |
|
7405 ms |
143700 KB |
#include <bits/stdc++.h>
#define L long long
using namespace std;
L n,q,x;
L a[400040];
priority_queue<L>numqueue[1000];
priority_queue<L,vector<L>,greater<L> >queryqueue[1000];
void update(L loc){
L i;
for(i=loc*x;i<(loc+1)*x&&i<n;i++)
{
if(!queryqueue[loc].empty()&&queryqueue[loc].top()<a[i])
{
L temp=a[i];
a[i]=queryqueue[loc].top();
queryqueue[loc].pop();
queryqueue[loc].push(temp);
}
}
priority_queue<L,vector<L>,greater<L> >temp;
swap(temp,queryqueue[loc]);
priority_queue<L>temp2;
swap(temp2,numqueue[loc]);
for(i=loc*x;i<(loc+1)*x&&i<n;i++)
{
numqueue[loc].push(a[i]);
}
}
L naive(L s,L e,L num){
L i;
for(i=s;i<=e&&i<n;i++)
{
if(num<a[i])
{
swap(num,a[i]);
}
}
priority_queue<L>temp;
swap(temp,numqueue[s/x]);
for(i=s/x;i<s/x+x&&i<n;i++)
{
numqueue[s/x].push(a[i]);
}
return num;
}
L give(L loc,L num){
queryqueue[loc].push(num);
numqueue[loc].push(num);
L ret=numqueue[loc].top();
numqueue[loc].pop();
return ret;
}
int main()
{
scanf("%lld %lld",&n,&q);
while(x*x<n) x++;
L i,j;
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
numqueue[i/x].push(a[i]);
}
for(i=1;i<=q;i++)
{
L s,e,num;
scanf("%lld %lld %lld",&s,&e,&num);
s--;
e--;
update(s/x);
update(e/x);
if(s<=e)
{
if(s/x==e/x)
{
printf("%lld\n",naive(s,e,num));
}
else
{
L temp=naive(s,s/x*x+x-1,num);
for(j=s/x+1;j<e/x;j++)
{
temp=give(j,temp);
}
printf("%lld\n",naive(e/x*x,e,temp));
}
}
else
{
L temp=naive(s,s/x*x+x-1,num);
for(j=s/x+1;j<(n-1)/x;j++)
{
temp=give(j,temp);
}
for(j=0;j<e/x;j++)
{
temp=give(j,temp);
}
printf("%lld\n",naive(e/x*x,e,temp));
}
}
}
Compilation message
telegraph.cpp: In function 'int main()':
telegraph.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&n,&q);
~~~~~^~~~~~~~~~~~~~~~~~~
telegraph.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[i]);
~~~~~^~~~~~~~~~~~~~
telegraph.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&s,&e,&num);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6356 ms |
143316 KB |
Output is correct |
2 |
Correct |
6173 ms |
143316 KB |
Output is correct |
3 |
Correct |
3220 ms |
143316 KB |
Output is correct |
4 |
Correct |
6113 ms |
143460 KB |
Output is correct |
5 |
Correct |
5345 ms |
143460 KB |
Output is correct |
6 |
Correct |
6588 ms |
143460 KB |
Output is correct |
7 |
Correct |
7047 ms |
143460 KB |
Output is correct |
8 |
Correct |
6347 ms |
143460 KB |
Output is correct |
9 |
Correct |
3342 ms |
143460 KB |
Output is correct |
10 |
Correct |
5316 ms |
143460 KB |
Output is correct |
11 |
Correct |
3113 ms |
143460 KB |
Output is correct |
12 |
Correct |
6247 ms |
143460 KB |
Output is correct |
13 |
Correct |
6656 ms |
143560 KB |
Output is correct |
14 |
Correct |
6116 ms |
143560 KB |
Output is correct |
15 |
Correct |
3721 ms |
143560 KB |
Output is correct |
16 |
Correct |
7304 ms |
143700 KB |
Output is correct |
17 |
Correct |
5501 ms |
143700 KB |
Output is correct |
18 |
Correct |
7405 ms |
143700 KB |
Output is correct |
19 |
Correct |
6807 ms |
143700 KB |
Output is correct |
20 |
Correct |
7136 ms |
143700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |