# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936789 | mostafa133 | Trol (COCI19_trol) | C++14 | 0 ms | 348 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 1e9 + 7;
ll au(string s)
{
vector<bool> v(10);
for (int i = 0; i < s.size(); i++)
{
if (v[s[i] - '0'])
{
return 0;
}
v[s[i] - '0'] = 1;
}
return 1;
}
int main()
{
fast;
// freopen("pails.in", "r", stdin);
// freopen("pails.out", "w", stdout);
ll q;
cin >> q;
while (q--)
{
ll l, r;
cin >> l >> r;
if (r - l < 9)
{
ll ans = 0;
for (ll i = l; i <= r; i++)
{
ans += (i % 9 == 0 ? 9 : i % 9);
if(i == 2016)
{
cout << ans;
}
}
cout << ans << '\n';
continue;
}
ll tmpl = l, tmpr = r;
while (tmpl % 9)
{
tmpl++;
}
while (tmpr % 9)
{
tmpr--;
}
ll ans = (tmpr - tmpl) / 9;
ans *= (9 * 5);
// cout << ans << ' ';
tmpl = l % 9, tmpr = r % 9;
for (int i = tmpl; i <= 9; i++)
{
ans += (i % 9 == 0 ? 9 : i % 9);
if(tmpl == 0)
break;
}
// cout << ans << ' ';
for(int i = 1; i <= tmpr; i++)
{
ans += (i % 9 == 0 ? 9 : i % 9);
}
cout << ans << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |