Submission #500741

#TimeUsernameProblemLanguageResultExecution timeMemory
500741sewon1407공장 (KOI13_factory)C11
20 / 20
373 ms15072 KiB
#include <stdio.h> int n; int seg[2100000]; int indexes[1000001]; int sum(int from, int to, int node, int start, int end) { if(from > end || to < start) return 0; if(from <= start && end <= to) return seg[node]; int mid = (start+end)/2; return sum(from, to, node*2, start, mid)+sum(from, to, node*2+1, mid+1, end); } void update(int i, int diff, int node, int start, int end) { if(i < start || i > end) return; seg[node] += diff; int mid = (start+end)/2; if(start == end) return; update(i, diff, node*2, start, mid); update(i, diff, node*2+1, mid+1, end); } int main() { int t, p; unsigned long long cnt = 0; scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d", &t); indexes[t] = i; } for(int i=0; i<n; i++) { scanf("%d", &t); p = indexes[t]; cnt += sum(p+1, n-1, 1, 0, n-1); update(p, 1, 1, 0, n-1); } printf("%llu", cnt); }

Compilation message (stderr)

factory.c: In function 'main':
factory.c:27:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &n);
      |     ^~~~~~~~~~~~~~~
factory.c:29:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d", &t);
      |         ^~~~~~~~~~~~~~~
factory.c:33:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d", &t);
      |         ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...