# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26209 | Extazy | Boat (APIO16_boat) | C++14 | 2000 ms | 119836 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 517;
const int TO = 1000000000;
const int KEY = 314487923;
const int MOD = (1e9) + 7;
int n;
pair < int, int > a[N];
unordered_map < int, int > it;
long long ans;
void update(int pos, int val) {
while(val<0) val+=MOD;
val%=MOD;
for(;pos<=TO;pos+=pos&(pos)) it[pos]+=val,it[pos]%=MOD;
}
int query(int pos) {
long long ans=1;
for(;pos>=1;pos-=pos&(-pos)) ans+=it[pos];
return ans%MOD;
}
int main() {
int i,j;
scanf("%d", &n);
for(i=1;i<=n;i++) {
scanf("%d %d", &a[i].first, &a[i].second);
}
for(i=1;i<=n;i++) {
//for(j=a[i].first;j<=a[i].second;j++) ans+=query(j-1)+1;
//for(j=a[i].first;j<=a[i].second;j++) update(j,1);
for(j=a[i].second;j>=a[i].first;j--) ans+=query(j-1),update(j,query(j-1)+query(j-1)-query(j));
}
ans%=MOD;
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |