# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
14441 |
2015-05-16T13:56:29 Z |
ansol4328 |
공장 (KOI13_factory) |
C++ |
|
402 ms |
16708 KB |
#include<stdio.h>
#include<algorithm>
struct A
{
int x, num;
};
int n, IT[2000002], check[1000002];
long long sum;
A m[500002];
int cmp(const A &a, const A &b)
{
return a.x<b.x;
}
void input()
{
int i, a;
scanf("%d",&n);
for(i=1 ; i<=n ; i++)
{
scanf("%d",&a);
check[a]=i;
}
for(i=1 ; i<=n ; i++)
{
scanf("%d",&a);
m[i].x=check[a];
m[i].num=i;
}
std::sort(m+1,m+1+n,cmp);
}
void insert(int p)
{
while(p!=0)
{
IT[p]++;
p/=2;
}
}
int find(int from, int to)
{
int s=0;
while(from<to)
{
if(from%2==1)
{
s+=IT[from];
from++;
}
if(to%2==0)
{
s+=IT[to];
to--;
}
from/=2, to/=2;
}
if(from==to) s+=IT[from];
return s;
}
void process()
{
int i, k=1;
while(k<n) k*=2;
k--;
for(i=1 ; i<=n ; i++)
{
insert(k+m[i].num);
sum+=find(k+m[i].num+1,k+n);
}
}
void output()
{
printf("%lld",sum);
}
int main()
{
input();
process();
output();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
16708 KB |
Output is correct |
2 |
Correct |
0 ms |
16708 KB |
Output is correct |
3 |
Correct |
0 ms |
16708 KB |
Output is correct |
4 |
Correct |
0 ms |
16708 KB |
Output is correct |
5 |
Correct |
0 ms |
16708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
16708 KB |
Output is correct |
2 |
Correct |
0 ms |
16708 KB |
Output is correct |
3 |
Correct |
7 ms |
16708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
16708 KB |
Output is correct |
2 |
Correct |
37 ms |
16708 KB |
Output is correct |
3 |
Correct |
47 ms |
16708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
16708 KB |
Output is correct |
2 |
Correct |
115 ms |
16708 KB |
Output is correct |
3 |
Correct |
159 ms |
16708 KB |
Output is correct |
4 |
Correct |
206 ms |
16708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
16708 KB |
Output is correct |
2 |
Correct |
267 ms |
16708 KB |
Output is correct |
3 |
Correct |
293 ms |
16708 KB |
Output is correct |
4 |
Correct |
402 ms |
16708 KB |
Output is correct |
5 |
Correct |
383 ms |
16708 KB |
Output is correct |
6 |
Correct |
365 ms |
16708 KB |
Output is correct |