Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- void parseDot(char s[100], int &first, int &second) {
- int length = strlen(s);
- int temp = 0, dotFound = 0, negative = 1;
- for (int i = 0; i < length; i++) {
- if (s[i] == '.') {
- first = temp;
- dotFound = 1;
- temp = 0;
- continue;
- }
- if (s[i] == '-') {
- negative = -1;
- continue;
- }
- temp = temp * 10 + (s[i] - '0');
- }
- second = -1;
- if (dotFound) {
- second = temp;
- } else {
- first = temp * negative;
- }
- }
- int main(void) {
- int t;
- cin >> t;
- int start, end, p_id, c_id, s_id, r_id, slot;
- char query;
- char s[100];
- // For any product (optionally )
- int stateSales[104][10000];
- int productSales[104][60];
- for (int i = 0; i < 104; i++) {
- for (int j = 0; j < 10000; j++)
- stateSales[i][j] = 0;
- for (int j = 0; j < 60; j++) {
- productSales[i][j] = 0;
- }
- }
- while (t--) {
- cin >> s;
- query = s[0];
- cin >> s;
- parseDot(s, start, end);
- cin >> s;
- parseDot(s, p_id, c_id);
- cin >> s;
- parseDot(s, s_id, r_id);
- //cout << query << " " << start << " " << end << " " << p_id << " " << c_id << " " << s_id << " " << r_id << endl;
- if (query == 'S') {
- // total sale on this day
- productSales[start][0] += 1;
- // For this specific product
- productSales[start][(p_id - 1) * 5 + 1] += 1;
- // For this specific product in this category
- if (c_id != -1) {
- productSales[start][(p_id-1) * 5 + 1 + c_id] += 1;
- }
- // For any sale that happened in this state
- stateSales[start][(s_id-1) * 26] += 1;
- // For any sale that happened in this state in this region
- if (r_id != -1)
- stateSales[start][(s_id-1) * 26 + r_id] += 1;
- // For any sale that happened in that state for this particular product
- stateSales[start][(p_id-1) * 910 + (s_id-1) * 26 + 182] += 1;
- // For any sale that happened in that state for this particular product
- // in this category
- if (c_id != -1)
- stateSales[start][(p_id - 1) * 910 + c_id * 182 + (s_id-1) * 26 + 182] += 1;
- // For sale that happened in that state for this particular product
- // in this particular region
- if (r_id != -1) {
- stateSales[start][(p_id-1) * 910 + (s_id-1) * 26 + r_id + 182] += 1;
- }
- // For sale that happened in that state for this particular product
- // in this particular region in this category
- if (r_id != -1 and c_id != - 1) {
- stateSales[start][(p_id-1) * 910 + c_id * 182 + (s_id-1) * 26 + r_id + 182] += 1;
- }
- } else {
- int ans = 0;
- if (end == -1)
- end = start;
- for (int i = start; i <= end; i++) {
- if (p_id == -1 and s_id == -1) {
- // all sales
- ans += productSales[i][0];
- } else if (s_id == -1 and p_id != -1 and c_id == -1) {
- // all sales of this product
- ans += productSales[i][(p_id-1) * 5 + 1];
- } else if (s_id == -1 and p_id != -1 and c_id != -1) {
- ans += productSales[i][(p_id-1) * 5 + c_id + 1];
- } else if (p_id == -1 and s_id != - 1 and r_id == -1) {
- // all sales in this state
- ans += stateSales[i][(s_id - 1) * 26];
- } else if (p_id == -1 and s_id != - 1 and r_id != -1) {
- // all sales in this state in this regin
- ans += stateSales[i][(s_id - 1) * 26 + r_id];
- } else if (p_id != -1 and c_id == -1 and s_id != -1 and r_id == -1) {
- ans += stateSales[i][(p_id-1) * 910 + (s_id-1) * 26 + 182];
- } else if (p_id != -1 and c_id == -1 and s_id != -1 and r_id != -1) {
- ans += stateSales[i][(p_id-1) * 910 + (s_id-1) * 26 + r_id + 182];
- } else if (p_id != -1 and c_id != -1 and s_id != -1 and r_id == -1) {
- ans += stateSales[i][(p_id - 1) * 910 + c_id * 182 + (s_id-1) * 26 + 182];
- } else
- ans += stateSales[i][(p_id-1) * 910 + c_id * 182 + (s_id-1) * 26 + r_id + 182];
- }
- cout << ans << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement